2010-01-23 91 views
8

我有这个XAML。如果我删除了StackPanel.Resources部分,我将获得在应用程序级别定义的样式。如果我把它放进去,那么我只能得到新的样式。WPF风格继承

如何让它结合本地和全球风格?

<Window x:Class="MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 

    <DockPanel> 
     <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" > 
      <StackPanel.Resources> 
       <Style TargetType="TextBlock" > 
        <Setter Property="Margin" Value="4" /> 
       </Style> 
       <Style TargetType="Button" > 
        <Setter Property="Margin" Value="4" /> 
       </Style> 
      </StackPanel.Resources> 
      <Border Padding="5" BorderBrush="Blue" BorderThickness="4" > 
       <StackPanel> 
        <TextBlock>Applications</TextBlock> 
        <Button>Open Issues</Button> 
        <Button>Services</Button> 
       </StackPanel> 
      </Border> 
     </StackPanel> 
     <StackPanel></StackPanel> 
    </DockPanel> 
</Window> 

如果有帮助,这是我如何定义globla样式。

<Application x:Class="Application" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    StartupUri="MainWindow.xaml"> 
    <Application.Resources> 
     <ResourceDictionary Source="ShinyBlue.xaml"/> 
    </Application.Resources> 
</Application> 

回答

14
To Combine the application Level + Local Resource 
本地资源定义

<Style TargetType="TextBlock" BasedOn="{StaticResource StyleA}" > 
       <Setter Property="Margin" Value="4" /> 
      </Style> 

这将使从应用水平,你的风格,以及地方一级

+0

如果应用程序级别样式没有什么名? – 2010-01-23 09:21:51

+0

你只是给BaseTypeName像“TextBlock” – 2010-01-23 09:31:34

+0

你的意思是像