[英]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.