【发布时间】:2017-12-01 18:10:23
【问题描述】:
我正在开发一个 VSIX(Visual Studio 扩展)项目。它包含一个 WPF 数据网格。我需要设置自定义 DataGrid 行突出显示颜色,当 DataGrid 变为非活动状态(失去焦点)时,基于 Visual Studio 主题。
虽然通过堆栈溢出找到了许多类似的问答,但我无法找到基于 Visual Studio 主题的解决方案。
我通过以下代码(样式)遇到了。但是它不满足我的要求,请帮助解决这个问题。
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="True" />
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=IsKeyboardFocusWithin}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<!--Following Background color has to be changed based on VS theme-->
<Setter Property="Background" Value="DarkGray" />
<Setter Property="Foreground" Value="{DynamicResource VsBrush.WindowText}" />
<!--This BorderBrush color has to be changed based on VS theme-->
<Setter Property="BorderBrush" Value="DarkGray"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
谢谢
【问题讨论】:
标签: c# wpf visual-studio-extensions vsix