gpt4 book ai didi

c# - DataGridCheckBoxColumn 在应用 ElementStyle 时丢失 IsReadOnly 状态

转载 作者:太空狗 更新时间:2023-10-30 01:01:41 25 4
gpt4 key购买 nike

我需要将 DataGridCheckBoxColumn 垂直居中。因为我没有在 DataGridCheckBoxColumn 中找到属性,所以我应用了一个 ElementStyle。但是,当应用此样式时,我的 CheckBox 再次变为可检查状态,尽管它在我的 DataGrid 中设置为 ReadOnly(整个 DatagridReadOnly),并且在 DataGridCheckBoxColumn 本身中。

如何创建一个垂直居中的 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>

最佳答案

当您在 DataGridCheckBoxColumn 上设置 ElementStyle 时,您应该包括 FrameworkElement.IsHitTestVisible="False"到你的风格:

<Setter Property="FrameworkElement.IsHitTestVisible" Value="False"/>

此外,如果您将 TargetType="CheckBox" 添加到 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>

关于c# - DataGridCheckBoxColumn 在应用 ElementStyle 时丢失 IsReadOnly 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37584559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com