我正在使用表达式黑暗WPF主题(http://wpfthemes.codeplex.com/)和ListView(视图属性设置为GridView)来显示一些用户数据,如下所示:
<ListView
Grid.Row="1"
ItemsSource="{Binding RegisteredUsers}"
SelectedItem="{Binding SelectedUser}"
>
<ListView.View>
<GridView>
<GridViewColumn
Header="Login"
DisplayMemberBinding="{Binding Login}"
Width="60"/>
<GridViewColumn
Header="Full Name"
DisplayMemberBinding="{Binding FullName}"
Width="180"/>
<GridViewColumn
Header="Last logon"
DisplayMemberBinding="{Binding LastLogon}"
Width="120"/>
<GridViewColumn
Header="Photo"
Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image
Source="{Binding Photo}"
Width="30"
Height="35"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
选择时行具有深色背景和白色背景的白色文本,但是文本颜色在选择时不会改变,并且难以阅读,我希望文本在选择行时具有深色。我搜索了一种设置文本颜色样式的方法,但没有成功,这里是ListViewItem的控件模板:
<Border SnapsToDevicePixels="true" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" x:Name="border">
<Grid Margin="2,0,2,0">
<Rectangle x:Name="Background" IsHitTestVisible="False" Opacity="0.25" Fill="{StaticResource NormalBrush}" RadiusX="1" RadiusY="1"/>
<Rectangle x:Name="HoverRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource NormalBrush}" RadiusX="1" RadiusY="1"/>
<Rectangle x:Name="SelectedRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource SelectedBackgroundBrush}" RadiusX="1" RadiusY="1"/>
<GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,2,0,2" VerticalAlignment="Stretch" />
</Grid>
</Border>
更改背景颜色的触发器仅应用动画来更改“SelectedRectangle”不透明度,但我无法更改同一触发器上的文本颜色(我尝试在ListViewItem上使用setter作为前景色,但没有成功)。
有人对此有所了解吗?
答案 0 :(得分:0)
尝试更改TextBlock.Foreground
<GridViewRowPresenter TextBlock.Foreground="{TemplateBinding Foreground}"/>
答案 1 :(得分:0)
通过在GridViewRowPresenter范围上应用文本块样式来解决管理:
<GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,2,0,2" VerticalAlignment="Stretch" >
<GridViewRowPresenter.Resources>
<Style
TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource {x:Type TextBlock}}"
>
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}}"
Value="True">
<Setter
Property="Foreground"
Value="Black"
/>
</DataTrigger>
</Style.Triggers>
</Style>
</GridViewRowPresenter.Resources>
</GridViewRowPresenter>