dimanche 10 mai 2020

WPF/C# - Throw away the Content for a Checkbox in a Datagrid

TL;DR How do I make a Checkbox not draw/include the label for the content or the space required for the label?

I'm using Visual Studio in conjunction with C# and WPF. I have a Checkbox in a DataTemplate inside of a DataGrid. My issue is that I suspect that while the Content is empty, the space for the content is still being taken up.

The end result is that I have a checkbox smashed to the left of the column, and a vast desert of whitespace to it's right

My current UI disaster looks like this:

Current UI

Right now, my XAML looks like the following. As you can see, I've tried messing around with the Horizontal and HorizontalContentAlignments with little to no luck.

 <DataGridTemplateColumn Header="Y/N">
   <DataGridTemplateColumn.CellTemplate>
     <DataTemplate>
       <CheckBox IsChecked="{Binding Path=IsSelected, UpdateSourceTrigger=PropertyChanged}" 
                                  HorizontalContentAlignment="Center">
         <TextBlock>
         </TextBlock>
       </CheckBox>
     </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>

I've tried setting the size of the DataGridTemplateColumn but I don't see it really centering the checkbox even with the Horizontal* attributes set which makes me think it's got the space for the Label in there.

Any help on this is greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire