WPF DataGrid 选定的行样式

标签 wpf datagrid styles

我遇到了一个非常愚蠢的问题 - 需要在 WPF DataGrid 中设置所选行的样式。

我想显示一个带有蓝色边框的矩形,而不是仅仅用某种颜色填充整行。

有什么想法可以实现吗?它只是必须有某种方法让它变得非常简单。

最佳答案

DataGrid 上使用CellStyleRowStyleDataGridCellDataGridRow 都有 IsSelected 属性,可在 Trigger 中使用该属性来确定它们是否被选中。

像下面这样的东西应该可以解决问题:

<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Style.Triggers>
            <Trigger Property="IsSelected"
                        Value="True">
                <Setter Property="Background"
                        Value="White" />
                <Setter Property="Foreground"
                        Value="Black" />
            </Trigger>
        </Style.Triggers>
    </Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">
        <Style.Triggers>
            <Trigger Property="IsSelected"
                        Value="True">
                <Setter Property="BorderBrush"
                        Value="Blue" />
                <Setter Property="BorderThickness"
                        Value="2" />
            </Trigger>
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

尝试一下,直到你做对为止。

关于WPF DataGrid 选定的行样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4539909/

相关文章:

html - 当我 "inspect element"时,CSS 代码的更改没有显示

.net - 当 IsEnabled=False 和 IsEditable = False 时,WPF 组合框选择的项目文本不会变灰

c# - WPF DataGrid - 数据绑定(bind)到 CellTemplates DataTemplate 中的 DataTable 单元格

c# - 如何使用绑定(bind)更改数据网格文本 block 列的前景

styles - Material-UI 主题 : How to manage order or priority the . MuiXXX 类是否应用?

wpf - 从datagrid中的一行中的选定单元格中删除边框

wpf - (多个)MultiDataTrigger 与转换器的效率

.net - 在 System.AddIn 中托管 WPF 时出现 NullReferenceException

c# - 保持 ObservableCollection 和 ObjectContext 同步的最佳方法?

wpf - 如何确保WPF数据网格的当前项可见?