【发布时间】:2014-03-27 15:46:55
【问题描述】:
为什么这种样式在 WPF 中不起作用? TextBlock 应该是红色的,但不是。它保持黑色。这只是在 TextBlock 位于模板中时发生。
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Red"></Setter>
</Style>
</Window.Resources>
<Grid>
<ListView>
<ListView.Items>
<ListItem></ListItem>
</ListView.Items>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock>Hallo</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
【问题讨论】:
-
似乎是一个错误:SO-Answer.