开发者

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?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜