C# uwpxaml中的全局样式
我在App.xaml中设置了一些样式C# uwpxaml中的全局样式,c#,xaml,uwp,uwp-xaml,C#,Xaml,Uwp,Uwp Xaml,我在App.xaml中设置了一些样式 <Style TargetType="TextBlock"> <Setter Property="Foreground" Value ="HotPink"/> </Style> 此样式适用于普通控件,但不适用于DataTemplates <TextBlock Text="Test"></TextBlock> <!-- Works here --> <ItemsCont
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value ="HotPink"/>
</Style>
此样式适用于普通控件,但不适用于DataTemplates
<TextBlock Text="Test"></TextBlock> <!-- Works here -->
<ItemsControl ItemsSource="{Binding ViewModel.UniverseGroups}" HorizontalAlignment="Right" VerticalAlignment="Center">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RelativePanel>
<TextBlock Text="{Binding Name}"></TextBlock>
<!-- This text still is black -->
</RelativePanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
是否有一种方法可以使全局样式甚至在数据模板内工作?不幸的是,没有,在您的情况下,它将被
ItemsControl
的前台
覆盖。因此,您必须将以下内容添加到App.xaml
<Style TargetType="ItemsControl">
<Setter Property="Foreground" Value ="HotPink"/>
</Style>
<Style TargetType="ListViewItem">
<Setter Property="Foreground" Value ="HotPink"/>
</Style>