使用密码框或任何形式的常规文本控件时,我似乎无法访问这些属性。我已经设置了一个值转换器,它在更新时正确返回值,但是一旦命令触发我的按钮,params似乎被重置为null。
XAML
<Button x:Name="RegisterButton" Content="register" Height="28" Margin="0,0,8,8" VerticalAlignment="Bottom" Background="#FF005D99" BorderBrush="White" Foreground="White" FontSize="13.333" TextOptions.TextFormattingMode="Display" FontFamily="/Agile Project Management Tool 2012;component/Fonts/#Segoe UI" Padding="1,0,1,1" HorizontalAlignment="Right" Width="90" Command="{Binding RegisterCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ParamConverter}">
<Binding ElementName="EmailTextInput" Path="Text"/>
<Binding ElementName="PhoneTextInput" Path="Text"/>
</MultiBinding>
</Button.CommandParameter>
</Button>
价值转换器
class TwoParamConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
查看模型
public ResigtrationViewModel()
{
_browsePicturesCommand = new DelegateCommand(OnBrowsePicturesCommand);
_registerCommand = new DelegateCommand<object>(OnRegisterCommand);
}
private void OnRegisterCommand(object paramaters)
{
var values = (object[])paramaters;
var a = (string)values[0];
var b = (string)values[1];
MessageBox.Show(a);
MessageBox.Show(b);
}
但是当我在OnRegisterCommand调用中检查Paramaters时,它们似乎是null。
任何帮助将不胜感激!
答案 0 :(得分:0)
试试这个
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//any checks and such things you can add yourself :)
return new Tuple<string,string>((string)values[0],(string)values[1]);
//or
//return values.ToArray()
}