vendredi 10 mars 2023

Make Checkbox in WPF checked by default

I have a DataGrid in a WPF page. For reasons to do with making it instantly clickable, I am not using <DataGridCheckboxColumn> but instead using a different way:

<DataGrid.Columns>
   <DataGridTextColumn Header="PathID" Binding="{Binding Path.PathID}" Width="2*"/>
   <DataGridTextColumn Header="Path" Binding="{Binding Path}" Width="5*"/>
   <DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="1*"/>
   <DataGridTextColumn Header="Item Name" Binding="{Binding Item}" Width="3*"/>
   <DataGridTextColumn Header="Type" Binding="{Binding Type}" Width="1*" IsReadOnly="True"/>
   <DataGridTemplateColumn Header="Write">
      <DataGridTemplateColumn.CellTemplate>
         <DataTemplate>
            <CheckBox IsChecked="{Binding Path=IsWriteChecked ,UpdateSourceTrigger=PropertyChanged}"></CheckBox>
         </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
   </DataGridTemplateColumn>
   <DataGridTextColumn Header="Write Value" Binding="{Binding WriteValue}" Width="2*" IsReadOnly="True"/>
</DataGrid.Columns>

That Checkbox column (called Write) is the one I want to be checked by default but I am not sure how to make this happen. Normally I would have IsChecked = true but the code example I used for the one click box found here: https://mikeborozdin.com/post/wpf-datagrid-checkbox-single-click-checkingunchecking/

This makes me use the IsChecked to set the Binding instead of setting it to True. Does anyone know how I would get the boxes to be checked by default here?




Aucun commentaire:

Enregistrer un commentaire