开发者

Resource Dictionary Styles not available to UserControl

开发者 https://www.devze.com 2023-04-07 23:57 出处:网络
So I have made a resource dictionary of styles to use and included it in my UserControl: <UserControl.Resources>

So I have made a resource dictionary of styles to use and included it in my UserControl:

<UserControl.Resources>
    <ResourceDictionary Source="../affinitySty开发者_如何学Goles.xaml" />
</UserControl.Resources>

Which makes it available to all the controls in the UserControl, but not the UserControl itself. I am guessing this is because that bit of code comes after the UserControl tag.

How can I use Resource Dictionary defined styles for my UserControl background?


One option is to use DynamicResource rather than StaticResource; this postpones resolution until runtime.

Alternately, you can use the following XAML property syntax and place it after the ResourceDictionary is merged in:

<UserControl.Background>
    <StaticResource ResourceKey="SomeResourceKey"/>
</UserControl.Background>
0

精彩评论

暂无评论...
验证码 换一张
取 消