【问题标题】:How to use Resource Dictionary by its Key?如何按键使用资源字典?
【发布时间】:2017-12-15 18:09:06
【问题描述】:

我正在尝试使用我的 Resource Dictionary,但它无法识别已创建的样式。

<Window.Resources>
    <RoutedUICommand x:Key="Add" Text="Add" />
    <RoutedUICommand x:Key="Cancel" Text="Cancel" />
    <RoutedUICommand x:Key="Exit" Text="Exit" />
    <ResourceDictionary x:Key="LightTheme" Source="/Themes/Light.xaml"/>
</Window.Resources>

当我从 ResourceDictionary 标记中删除 x:Key 时,它会显示一条消息“每个字典都必须有一个关联的键

但是当我尝试使用我的一种样式时,它不起作用。

<Button x:Name="AddNew" Style="{StaticResource RoundCorner}">

【问题讨论】:

    标签: wpf resourcedictionary


    【解决方案1】:

    合并字典。为此,您需要有一个显式的 ResourceDictionary 元素。

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Themes/Light.xaml"/>
            </ResourceDictionary.MergedDictionaries>
    
            <RoutedUICommand x:Key="Add" Text="Add" />
            <RoutedUICommand x:Key="Cancel" Text="Cancel" />
            <RoutedUICommand x:Key="Exit" Text="Exit" />
    
        </ResourceDictionary>
    </Window.Resources>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多