Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# uwpxaml中的全局样式_C#_Xaml_Uwp_Uwp Xaml - Fatal编程技术网

C# uwpxaml中的全局样式

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

我在App.xaml中设置了一些样式

<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>