有没有人知道如何在Visual Studio工具窗口中正确设置WPF ListView的样式,以便它能够正确响应活动的Visual Studio主题?
我正在尝试在VS任务列表工具窗口中实现类似的东西:
我发现这种风格VsResourceKeys.ThemedDialogListViewItemGridStyleKey但它不会产生类似的东西。
这是我到目前为止所取得的成就:
几乎一切都错了:
列表视图在XAML中定义如下:
<ListView
x:Name="listDetails"
Grid.Row="4"
Height="150"
Style="{StaticResource ResourceKey={x:Static theming:StyleKeys.ThemedListViewDefaultStyleKey}}"
>
<ListView.View>
<GridView>
<GridViewColumn
Header="Property"
Width="150"
DisplayMemberBinding="{Binding PropertyName}"
HeaderContainerStyle="{StaticResource ResourceKey={x:Static theming:StyleKeys.ThemedListViewGridViewColumnHeaderDefaultStyleKey}}"
/>
<GridViewColumn
Header="Type"
Width="150"
DisplayMemberBinding="{Binding TypeName}"
HeaderContainerStyle="{StaticResource ResourceKey={x:Static theming:StyleKeys.ThemedListViewGridViewColumnHeaderDefaultStyleKey}}"
/>
<GridViewColumn
Header="Left Value"
Width="150"
DisplayMemberBinding="{Binding LeftValue}"
HeaderContainerStyle="{StaticResource ResourceKey={x:Static theming:StyleKeys.ThemedListViewGridViewColumnHeaderDefaultStyleKey}}"
/>
<GridViewColumn
Header="Right Value"
Width="150"
DisplayMemberBinding="{Binding RightValue}"
HeaderContainerStyle="{StaticResource ResourceKey={x:Static theming:StyleKeys.ThemedListViewGridViewColumnHeaderDefaultStyleKey}}"
/>
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ResourceKey={x:Static theming:StyleKeys.ThemedListViewItemDefaultStyleKey}}" />
</ListView.ItemContainerStyle>
</ListView>
样式定义如下:
<Style
x:Key="{x:Static theming:StyleKeys.ThemedListViewDefaultStyleKey}"
TargetType="{x:Type ListView}"
>
<Setter Property="Background" Value="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowBackgroundBrushKey}}" />
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style
x:Key="{x:Static theming:StyleKeys.ThemedListViewItemDefaultStyleKey}"
TargetType="{x:Type ListViewItem}"
BasedOn="{StaticResource ResourceKey={x:Static vsshell:VsResourceKeys.ThemedDialogListViewItemGridStyleKey}}"
>
</Style>
<Style
x:Key="{x:Static theming:StyleKeys.ThemedListViewGridViewColumnHeaderDefaultStyleKey}"
TargetType="{x:Type GridViewColumnHeader}"
>
<Setter Property="Background" Value="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowBackgroundBrushKey}}" />
</Style>
是否有任何默认样式来实现正确的行为?或者关于样式中要改变什么的任何文档?
答案 0 :(得分:1)
VS Color Service和Shared VS Colors上有一些文档。共享vs颜色文档应该足以为您提供正确的颜色名称以用于您的控件。
通常,您需要为控件设置前景色,背景色和边框色。然后,让触发器根据选择,鼠标悬停,禁用等改变这些颜色
只要您使用VS Color Service,您的UI颜色将自动更改为高对比度模式,因此您无需自己处理。