如何在 MaterialDesignThemes 中覆盖此 DataGrid 样式属性?
Posted
技术标签:
【中文标题】如何在 MaterialDesignThemes 中覆盖此 DataGrid 样式属性?【英文标题】:How could I overwrite this DataGrid style property in MaterialDesignThemes? 【发布时间】:2021-11-24 16:51:58 【问题描述】:I'm using material design in XAML, I have a DataGrid, and when a row is selected and the mouse leaves the row then the row's background changes to white, if the mouse returns it changes back to the original color.我想我已经找到了设置它的代码部分,但我似乎无法覆盖它...... 这是“MaterialDesignDataGridCell”风格,对我来说似乎是这样设置的。
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="Binding IsSelected, RelativeSource=RelativeSource Self" Value="True"/>
<Condition Binding="Binding IsMouseOver, RelativeSource=RelativeSource AncestorType=DataGridRow" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="DynamicResource MaterialDesignSelection" />
</MultiDataTrigger>
我尝试复制此触发器并设置不同的值,仅在鼠标悬停为 false 时设置触发器以设置背景,并尝试设置这些但没有运气:
<Style.Resources>
<SolidColorBrush x:Key="x:Static SystemColors.HighlightBrushKey" Color="Black" />
<SolidColorBrush x:Key="x:Static SystemColors.ControlBrushKey" Color="Black" />
<SolidColorBrush x:Key="x:Static SystemColors.InactiveSelectionHighlightBrushKey" Color="Black"/>
</Style.Resources>
【问题讨论】:
你想改变颜色还是你想做什么? 【参考方案1】:不太确定您想要实现什么,但如果您想覆盖数据网格单元格的单元格样式,您可以这样做
<DataGrid>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell" BasedOn="StaticResource MaterialDesignDataGridCell">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="Binding IsSelected, RelativeSource=RelativeSource Self" Value="True"/>
<Condition Binding="Binding IsMouseOver, RelativeSource=RelativeSource AncestorType=DataGridRow" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Red" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
【讨论】:
我会发誓我就这样拥有它,但它猜它搞砸了,这就是我要找的,我很感激,谢谢!以上是关于如何在 MaterialDesignThemes 中覆盖此 DataGrid 样式属性?的主要内容,如果未能解决你的问题,请参考以下文章
应用程序使用统计信息 – .NET CORE(C#) WPF界面设计