Styling UserControl in WPF from another assembly

I have a WPF user control defined in an application assembly. I am trying to customize a style-based user control to another (skin or theme). I do not want the theme / skin assembly to contain a resource dictionary with all styles to reference the application assembly. Is there any way to do this? For instance.

WPFApplication Collection

MyUserControl.xaml <- WPF user management

Thematic assembly

MyStyles.xaml <- WPF Resource Dictionary

I guess I can use

<Style x:Key="MyStyle">
    <Setter Property="Background" Value="Red" />
</Style>

in resourcecedictionary MyStyles.xaml and use:

<l:MyUserControl Name="control" Style="{StaticResource MyStyle}" />

in any window that uses MyUserControl.xaml in the WPFApplication assembly

However, I would prefer to target the user control in MyStyles.xaml resourcedictionary:

<Style TargetType="{x:Type l:MyUserControl}" x:Key="MyStyle">
        <Setter Property="Background" Value="Red" />
    </Style>

Is it possible?

+3
1

, . SO, , . ControlTemplates, .

, , , , , StaticResources xaml, /.

+1

Source: https://habr.com/ru/post/1728450/


All Articles