【发布时间】:2011-11-03 15:05:26
【问题描述】:
如何在命令参数中传递多个参数。
这是我想要做的: 我想发送是否选中(我可以通过将布尔字段引入对象绑定来做到这一点。但我不想这样做)并且我想发送该行的选定数据对象。
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}}, Path=DataContext.LineItemSelection}">
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource CommandConverter}">
<Binding Path="IsChecked" />
<Binding RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</CheckBox.CommandParameter>
</CheckBox>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
更新:
我添加了一个名为 selection Item 的类。看看转换器得到了什么。
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
SelectionItem si = new SelectionItem();
foreach (var value in values)
{
Type t = value.GetType();
if (t.FullName == "System.Boolean")
si.IsSelected = (bool) value;
else
{
si.SelectedCustomer = value as Customer;
}
}
return si;
}
如果我使用第二个参数的类型是复选框本身
<Binding RelativeSource="{RelativeSource Self}"/>
这里我想要绑定到该行的数据项(在本例中为客户)。 我什至尝试使用
<Binding RelativeSource= "{RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewColumn}}" Path="DataContext" />
但这也以 null 的形式出现。这是为什么?
【问题讨论】:
标签: wpf data-binding telerik mvvm-light telerik-grid