如何將兩個參數從XAML(一個Type對象和一個Model {Binding}
)傳遞給ViewModel作爲CommandParameter。我遇到過不同的帖子,但都使用控制綁定。有沒有什麼方法可以傳遞Type。將多個參數(包括類型)傳遞給WPF中的ViewModel
我想是這樣的:
<MenuItem x:Key="RuleBase" Header="RuleBase" x:Shared="False"
Command="{Binding DataContext.AddRuleCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
<MenuItem.CommandParameter>
<MultiBinding Converter="{StaticResource MultiParameterConverter}">
<Binding Path="{Binding}" />
<Binding Path="{x:Type local:RuleBase}" />
</MultiBinding>
</MenuItem.CommandParameter>
</MenuItem>
這段代碼正在與單獨一個參數:
<MenuItem x:Key="RuleBase" Header="RuleBase" x:Shared="False"
Command="{Binding DataContext.AddRuleCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
CommandParameter="{x:Type local:RuleBase}" />
那麼你發佈的第一個代碼塊並不適合你?因爲它看起來對我很好。除了你可能想要刪除第一個'CommandParameter =「{x:Type local:RuleSet}」',因爲當你將它與' ...一起使用時,你定義了兩次。你還可以發佈你的MultiParameterConverter嗎? –
對不起,有錯字,我已經糾正並從第一個代碼塊中刪除單個命令參數。 –
沒有'{Binding}'指的是與'MenuItem'關聯的模型。 –