简体   繁体   English

如何在ResourceDictionary中设置可用于背景属性的主要颜色

[英]How do I set a primary color that I can use for my background property in ResourceDictionary

So I created a ResourceDictionary that looks like this 所以我创建了一个看起来像这样的ResourceDictionary

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <SolidColorBrush x:Key="PrimaryColor" Color="#252525"/>
</ResourceDictionary>

Now my question is how do I get a hold of that key so I can use it for my background property on my MainWindow? 现在我的问题是我如何获得该密钥,以便我可以将它用于我的MainWindow上的background属性?

<Window ...
        Background="{DynamicResource PrimaryColor}">

You need to merge the ResourceDictionary into your App.xaml : 您需要将ResourceDictionary合并到App.xaml

<Application ...>
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="YourResourceDict.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Once it's in scope, you could reference any resource using either {DynamicResource key} or {StaticResource key} 一旦它在范围内,您可以使用{DynamicResource key}{StaticResource key}引用任何资源

What's the difference between StaticResource and DynamicResource in WPF? WPF中的StaticResource和DynamicResource有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为ItemContainerStyle创建ResourceDictionary? - How do I create a ResourceDictionary for my ItemContainerStyle? 如何将ResourceDictionary中的SolidColorBrush的Color属性绑定到ViewModel Color属性 - How could I bind a SolidColorBrush's Color property in a ResourceDictionary to a ViewModel Color property 如何从另一个程序集中将URI设置为ResourceDictionary中的对象? - How do I set the URI to an object in a ResourceDictionary from another assembly? 如何覆盖在ResourceDictionary中指定的DataGridColumnHeader? - How do I override the DataGridColumnHeader specified in my ResourceDictionary? 当我的文本框在resourcedictionary中时,如何保存文本输入? - How can I save text input when my textbox is in resourcedictionary? 在Windows Phone 8中,如何获取按钮的背景颜色属性? - In Windows Phone 8, How can i get the Background Color property of a button? 我可以在WinRT中更改主图块的背景颜色吗? - Can I change the background color of the primary tile in WinRT? 如何设置DataGridView中单个单元格的背景颜色? - How can I set the background color of individual cells in a DataGridView? 如何将纯色设置为整个菜单的背景? - How can I set a solid color as background for the ENTIRE menu? 如何更改 TabControl 的背景颜色? - How can I change the background color of my TabControl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM