wpf - App.xaml 中的合并字典

标签 wpf xaml app.xaml mergeddictionaries

我在一个单独的 .xaml 中有一堆 Xaml 矢量图标.我将它们装入我的 window使用这个指令:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/ScreenToGif;component/Themes/IconSet.xaml"></ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

我有很多窗口,所以我想简单地将此代码放在 App.xaml 中。 .

我正在尝试这个:
<Application.Resources> <!-- Error, The property "Resources" can only be set once. -->
    <ResourceDictionary x:Key="IconSet"> <!--Not sure why this?-->
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Mine;component/Themes/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

<!--Here goes the rest of the file, with Style and DropShadowEffect... -->
</Application.Resources>

所以这里的问题是:

所有示例都不使用 x:Key属性,但它给了我一个错误,说我需要。
当我这样做时,它说我不能拥有多个属性 Resource ...

最佳答案

请看注释文字

<Application.Resources>    
    <ResourceDictionary>           
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Mine;component/Themes/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>

        <!--You have to add other style here only-->

    </ResourceDictionary>

<!--Not Here-->

</Application.Resources>

关于wpf - App.xaml 中的合并字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27215155/

相关文章:

c# - 循环 xaml 元素

silverlight - Windows Phone 7 应用程序中较小的 PanoramaItems

wpf - App.Xaml的 View 模型

c# - 如何将 Application.Resources 移动到外部程序集?

c# - 访问由另一个线程添加的字典项

c# - 是否可以在浏览器上运行 WPF 应用程序?

c# - 调用异步方法和 Task.Run 异步方法之间的区别

wpf - App xaml假设实例化的第一个窗口是主窗口(showdialog被忽略),我需要显示多个窗口

c# - WPF .NET4.0 内容控件超出屏幕

c# - 绑定(bind)文本框 enter press to reactive command