【发布时间】:2017-04-11 02:10:18
【问题描述】:
我正在尝试将复选框置于数据网格单元格的中心。
我似乎无法想出一种在不同 Windows 主题中工作的方法来使其居中。例如,我可以将它居中,这样它在经典 Windows 主题中看起来不错,但在 Windows 7 Basic 主题下它是关闭的。
<DataGridCheckBoxColumn ElementStyle="{StaticResource CenteredCheckStyle}" MinWidth="15"
CellStyle="{StaticResource SingleClickEditing}" Visibility="{Binding exists}"
Binding="{Binding Path=toTransfer, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False"
CanUserSort="False" CanUserResize="false" CanUserReorder="false">
<DataGridCheckBoxColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Checked"
HorizontalContentAlignment="Center" HorizontalAlignment="Center"
IsThreeState="False" Margin="8,0,0,0" Loaded="CheckBox_Loaded"/>
</StackPanel>
</DataTemplate>
</DataGridCheckBoxColumn.HeaderTemplate>
</DataGridCheckBoxColumn>
【问题讨论】:
-
不要使用那个保证金 8,0,0,0...
-
如果我去掉 Margin,它在经典中看起来不错,如果我添加它,它在 Windows 7 Basic 中看起来不错
-
如果你不需要所有 DataGrid 的东西,你可以试试 'HeadedItemsControl',stackoverflow.com/questions/32453131/…
标签: wpf xaml checkbox datagrid