我需要垂直居中DataGridCheckBoxColumn
。因为我没有找到里面的房产DataGridCheckBoxColumn
,我应用了ElementStyle
。然而,当应用这种风格时,我的CheckBox
再次变为可检查,尽管它被设置为ReadOnly
in my DataGrid
(整体Datagrid
is ReadOnly
),并在DataGridCheckBoxColumn
itself.
如何创建垂直居中的CheckBox
保持其ReadOnly
状态?这是我的代码:
<DataGrid IsReadOnly="True">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Test" IsReadOnly="True" Binding="{Binding MyBinding}">
<DataGridCheckBoxColumn.ElementStyle>
<Style>
<Setter Property="FrameworkElement.Margin" Value="0,1,0,0" />
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center" />
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center" />
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>
当你设置ElementStyle
on the DataGridCheckBoxColumn
你应该包括FrameworkElement.IsHitTestVisible="False"给你的Style
:
<Setter Property="FrameworkElement.IsHitTestVisible" Value="False"/>
另外如果你添加TargetType="CheckBox"
to the Style
那么你就不必重复FrameworkElement
对于每个Setter
不再:
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="0,1,0,0" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="IsHitTestVisible" Value="False"/>
</Style>
</DataGridCheckBoxColumn.ElementStyle>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)