Sierra313
Sierra313

Reputation: 75

Wpf xaml inheritance

Is it possible to inherit same style for a ControlTemplate in two different windows? I'm new to wpf and I'm not sure how to do it or even if it's 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 like this:

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

How do I import the style from the first window?

Upvotes: 3

Views: 668

Answers (1)

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50752

Yes it is possible, you can move style to app.xaml, and both windows will see that 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

Upvotes: 4

Related Questions