最近碰到一个问题,在MVVM模式下进行命令传参时需要传递两个参数:例如类型和ID
解决方法如下
<i:Interaction.Triggers> <i:EventTrigger EventName="SelectedItemChanged"> <i:InvokeCommandAction Command="{Binding SelectChangedCommand}"> <i:InvokeCommandAction.CommandParameter> <MultiBinding Converter="{StaticResource treeNodeParameterConvert}"> <Binding ElementName="TreeView" Path="SelectedItem.NodeType" /> <Binding ElementName="TreeView" Path="SelectedItem.NodeId" /> </MultiBinding> </i:InvokeCommandAction.CommandParameter> </i:InvokeCommandAction> </i:EventTrigger> </i:Interaction.Triggers>
然后定义一个转换器:
public class TreeNodeParameterConvert : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { return values.Clone(); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
解决问题
标签:MVVM,多个,object,culture,参数,Type,public,CultureInfo From: https://www.cnblogs.com/TheXiang/p/16734556.html