当我尝试将 DataGrid 中的复选框绑定到 View Model 的公共属性(即用户控件的数据上下文)时,您是否看到我的代码有任何问题。
谢谢,
江当
<Custom:DataGrid ItemsSource="{Binding Customers}"
AlternatingRowBackground="AliceBlue"
AutoGenerateColumns="False"
MaxHeight="250"
CanUserAddRows="False"
CanUserDeleteRows="False" >
<Custom:DataGrid.Columns>
<Custom:DataGridTemplateColumn>
<Custom:DataGridTemplateColumn.Header>
<WrapPanel>
<CheckBox IsChecked="{Binding Path=IsCheckAll, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},
UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock>Select<LineBreak/>UnSelect</TextBlock>
</WrapPanel>
</Custom:DataGridTemplateColumn.Header>
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=Selected, Mode=TwoWay}"/>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>