Inheritance wpf xaml

Can I inherit the same style for a ControlTemplate in two different windows? I am new to wpf and am not sure how to do this or even if it is possible. For example, if I have in Window1.xaml:

<Window.Resources>
    <ControlTemplate x:Key="myStyle" TargetType="Button">
        ...
    </ControlTemplate>
</Window.Resources>

And in Window2.xaml I want to use it as follows:

<Grid>
    <Grid.Resources>
        <Style TargetType="Button" BasedOn="{StaticResource myStyle}">
            ...
        </Style>
    </Grid.Resources>
<Grid>

How to import a style from the first window?

+3
source share
1 answer

Yes, maybe you can move the style in app.xaml and both windows will see this style

something like this in app.xaml

<Application.Resources>
 <ResourceDictionary>
    <Style x:Key="myStyle" TargetType="Button">
        ...
    </Style>
    <Style TargetType="Button" BasedOn="{StaticResource myStyle}">
        ...
    </Style>
 </ResourceDictionary>
</Application.Resources>

and both windows will see that style

+4
source

All Articles