如何将两个参数从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'关联的模型。 –