我现在想传两个控件到一ViewModel,可是ViewModel的方法参数一直为null,取不到任何值。
有什么好的办法吗?
我的源码是这样的:
<Window.Resources>
<local:DataConverter x:Key="dataConverter"/>
</Window.Resources>
<Button Header="添加用户" Icon="Images\Green.png" LargeIcon="Images\GreenLarge.png" x:Name="BtnAddUser" Command="{Binding AddUserCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{ StaticResource ResourceKey=dataConverter}" Mode="TwoWay">
<MultiBinding.Bindings>
<Binding ElementName="BtnAddUser"/>
<Binding ElementName="dockManager "/>
</MultiBinding.Bindings>
</MultiBinding>
</Button.CommandParameter>
</Button>
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace TLAgent.SecurityManager.WPF.MultiBindings
{
public class DataConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public static object ConverterObject;
public object Convert(object[] values, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
ConverterObject = values;
return values;
}
public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}
------解决方案--------------------
在Convert 返回的时候新 new 一个object 返回就行了