在ViewModel
内检查Checkbox
时,我似乎无法在DataGrid
内部启动方法。
每行中都有一个Checkbox
,当选择/取消选择Checkbox
时,我想在我的ViewModel
中触发一个更新数据库的方法。< / p>
我的XAML中有Datagrid
:
<DataGrid x:Name="dg_chapters" ItemsSource="{Binding Chapters}" SelectedItem="{Binding Chapter}" SelectionMode="Single" Background="Transparent" BorderBrush="#e5e5e5" CellStyle="{StaticResource episodeDataGridCell}" RowHeaderWidth="0" GridLinesVisibility="None" HorizontalAlignment="Stretch" Grid.Row="4" VerticalAlignment="Stretch" AutoGenerateColumns="False" Grid.RowSpan="1" Grid.Column="1" Grid.ColumnSpan="7">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Description}" CanUserResize="False" ClipboardContentBinding="{x:Null}" Header="Chapter" Width="90"/>
<DataGridTextColumn Binding="{Binding Appearance}" CanUserResize="False" ClipboardContentBinding="{x:Null}" Header="Player" Width="90"/>
<DataGridTextColumn Binding="{Binding Channel}" CanUserResize="False" ClipboardContentBinding="{x:Null}" Header="Channel" Width="100"/>
<DataGridTextColumn Binding="{Binding Mode}" ClipboardContentBinding="{x:Null}" Header="Mode" Width="80"/>
<DataGridCheckBoxColumn Binding="{Binding Protected}" Header="Protected" Width="80"/>
</DataGrid.Columns>
</DataGrid>
正如您在底部看到的是我的Checkbox
列。在我的ViewModel
我尝试创建一个命令来处理Checkbox
的选定/取消选择:
public ICommand Protected
{
get { return new DelegateCommand<object>(Protected_Click); }
}
然后我创建了Protected方法:
private void Protected_Click(object obj)
{
//DOES NOT HIT.
}
任何人都可以看到我出错的地方以及如何让这项功能发挥作用?
答案 0 :(得分:0)
DataGridTemplateColumn中的DataGrid内部复选框
<DataGrid Name="GatewayDataGrid" Width="auto" Height="auto">
<DataGridTemplateColumn Header="SplitMark" Width="30" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="Chb" VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding IsSelected,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="Chb_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Top"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"> </DataGridTextColumn >
<DataGridTextColumn Header="Department" Binding="{Binding Department}"> </DataGridTextColumn >
</DataGrid>