【问题标题】:Wpf xaml inheritanceWpf xaml 继承
【发布时间】:2011-03-19 02:01:58
【问题描述】:

是否可以在两个不同的窗口中为 ControlTemplate 继承相同的样式? 我是 wpf 的新手,我不知道该怎么做,或者即使它是可能的。 例如,如果我在 Window1.xaml 中有:

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

在 Window2.xaml 中我想这样使用它:

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

如何从第一个窗口导入样式?

【问题讨论】:

    标签: wpf xaml


    【解决方案1】:

    是的,可以,您可以将样式移动到 app.xaml,两个窗口都会看到该样式

    app.xaml 中的类似内容

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

    两个窗口都会看到该样式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      相关资源
      最近更新 更多