为什么这个多重绑定不起作用
我从我的复选框命令发送了多个参数。我用过转换器。代码如下。如果我放置一个调试器并看到这里的值是我的结果:
当选中或取消选中复选框检查时:
在转换器中它有值(项目对象和布尔值的数组)。但是当我来到我的方法时,该值是一个 object[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>
Converter:
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();
}
}
查看模型命令代码:
public ICommand SelectUnSelect
{
get { return new RelayCommand<object>(parm => this.SelectAndUnSelect(parm));}
}
如果我将调试器放在 SelectAndUnSelect 方法中,它会在 parm 中显示 object[2] 但两者其中为空。
观察:如果我将命令参数绑定到任何一个绑定,它就可以正常工作。
我在这里缺少什么?
- 香卡
I have sending multiple parameters from my Checkbox Command. I have used a converter. The code is below. If i put a debugger and see the values here are my results :
When checkbox check is either checked or unchekcked :
In the converter it has teh values (Array of the item object and boolean). But when i come to my method, the value is a object[2] but both values are 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>
Convertor :
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();
}
}
View Model Command Code :
public ICommand SelectUnSelect
{
get { return new RelayCommand<object>(parm => this.SelectAndUnSelect(parm));}
}
If i put a debugger in SelectAndUnSelect method, it shows me object[2] in parm but both of them are null.
Observation : If i bind my command parameter to any one of the bindings it works fine.
What am i missing here ?
- Shankar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前也遇到过同样的问题,如果我没记错的话,返回
values.ToList()
而不仅仅是values
应该可以解决它I've had the same problem before, if I remember correctly then returning
values.ToList()
instead of justvalues
should fix it