如何从另一个 xaml 样式表引用 xaml 样式表

How to reference xaml stylesheet from another xaml stylesheet

我有一个名为 Styles.xaml 的样式表,它具有所有初始样式,但随着时间的推移变得如此混乱。现在我要介绍第二种样式 Styles2.xaml,我想将颜色元素从 Styles.xaml 移动到 Styles2.xaml 并让 Styles.xaml 引用来自 Styles2.xaml[= 的颜色元素18=]

您使用 MergedDictionary 语法添加对它的引用,假设下面的代码来自 Style2.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Kliva.XAMLResources">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Styles.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Name="KlivaButton"
           TargetType="Button">
        <Setter Property="Background" Value="{StaticResource KlivaDarkBrush}" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="FontFamily" Value="{StaticResource OpenSansFontLight}" />
        <Setter Property="FontSize" Value="22" />
    </Style>

</ResourceDictionary>