我试图像下面那样将命令绑定到 RadGridView的列标题中出现的复选框。
<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsSelected, Mode=TwoWay}" Width="85" AutoSelectOnEdit="True" EditTriggers="CellClick">
<telerik:GridViewCheckBoxColumn.Header>
<CheckBox Command="{Binding ShowAllInDTCClickedCommand}" Content="Sh">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ShowAllInDTCCheckedCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding ShowAllInDTCUncheckedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</telerik:GridViewCheckBoxColumn.Header>
</telerik:GridViewCheckBoxColumn>
并尝试在 ViewModel 中实现,如下所示。
public DelegateCommand ShowAllInDTClickedCommand { get; set; }
public DelegateCommand ShowAllInDTCCheckedCommand { get; set; }
public DelegateCommand ShowAllInDTCUncheckedCommand { get; set; }
ShowAllInDTClickedCommand = new DelegateCommand(ShowAllInDTClicked);
ShowAllInDTCCheckedCommand = new DelegateCommand(ShowAllInDTCChecked);
ShowAllInDTCUncheckedCommand = new DelegateCommand(ShowAllInDTCUnchecked);
private void ShowAllInDTClicked()
{
//Do Something
}
private void ShowAllInDTCChecked()
{
//Do Something
}
private void ShowAllInDTCUnchecked()
{
//Do Something
}
但是这些命令无法执行,即根本无法访问代码。 我缺少什么?
答案 0 :(得分:1)
如果在视图模型中定义了DelegateCommand
属性,则应这样绑定它们:
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding DataContext.ShowAllInDTCCheckedCommand,
RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"/>
</i:EventTrigger>