- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要将 DataGridCheckBoxColumn
垂直居中。因为我没有在 DataGridCheckBoxColumn
中找到属性,所以我应用了一个 ElementStyle
。但是,当应用此样式时,我的 CheckBox
再次变为可检查状态,尽管它在我的 DataGrid
中设置为 ReadOnly
(整个 Datagrid
是 ReadOnly
),并且在 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/
我的用户界面中有一个数据网格。数据表将绑定(bind)到它。因为数据表可能有不同的格式,所以我在代码后面为网格添加列和绑定(bind)值。见下文: for (int iLoop = 0; iLoop
我遇到了以下问题,我不知道我的错在哪里。我指定了一个带有 DataGridComboBoxColumn 的 DataGrid 并设置了一个简单的 ElementStyle,它应该为非编辑模板的文本着色
我正在尝试更改 ElementStyle的 DataGrid ComboBox 列。据说 Style 的类型确实是 TextBlock当控件未被编辑时。因此,如其他示例所示,我尝试过:
我需要将 DataGridCheckBoxColumn 垂直居中。因为我没有在 DataGridCheckBoxColumn 中找到属性,所以我应用了一个 ElementStyle。但是,当应用此样式
我是一名优秀的程序员,十分优秀!