I have a custom column I am trying to make in WPF.
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.Header>
<CheckBox x:Name="checkAll" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"></CheckBox>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="#" Binding="{Binding userFriendlyId}" IsReadOnly="True"/>
<DataGridTextColumn Header="Log Number" Binding="{Binding logNumber}" />
</DataGrid.Columns>
Both of the DataGridTextColumns
are correctly bound to properties of my object and if I swap out my custom column for a DataGridCheckboxColumn
it binds properly. I am trying to use this column because I want to have a check all/uncheck all option for the datagrid. Also it only takes one click to trigger these checkboxes as opposed to using the DataGridCheckboxColumn
.
I use this code to asssign the ItemSource of the data grid:
DataGrid.ItemsSource = samples;
DataGrid.Items.Refresh();
I also currently have this.DataContext = this;
although that doesn't seem to be making any sort of difference.
EDIT: Data Model that is displaying in the grid:
public class Sample
{
public bool isSelected { get; set; }
public int userFriendlyId { get; set; }
public string logNumber { get; set; }
}
答案 0 :(得分:0)
将绑定设置为IsChecked="{Binding isSelected}"
绑定中的属性名称区分大小写,因此如果对象模型使用isSelected
,则绑定也应该是绑定。