我从Checkbox命令发送了多个参数.我用过转换器.代码如下.如果我放一个调试器,看到这里的值是我的结果:
选中或取消选中复选框检查时:
在转换器中它有teh值(项目对象的数组和布尔值).但是当我来到我的方法时,值是一个对象[2],但两个值都是NULL
CheckBox XAML
<CheckBox x:Name="checkBox"
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Data.Label}"
ClickMode="Release"
Command="{Binding Path=DataContext.SelectUnSelect}">
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource SelectedItemConverter}">
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content.Data"/>
<Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"/>
</MultiBinding>
</CheckBox.CommandParameter>
Run Code Online (Sandbox Code Playgroud)
转换器:
public class CheckConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return values;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
查看型号命令代码:
public ICommand SelectUnSelect
{
get { return new RelayCommand<object>(parm => this.SelectAndUnSelect(parm));}
}
Run Code Online (Sandbox Code Playgroud)
如果我在SelectAndUnSelect方法中放置一个调试器,它会在parm中显示对象[2],但它们都是null.
观察:如果我将我的命令参数绑定到任何一个绑定,它工作正常.
我在这里失踪了什么?
我之前遇到过同样的问题,如果我没记错,那么返回values.ToList()而不是values应该修复它
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.ToList();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3439 次 |
| 最近记录: |