开发者

WPF Style Inheritance

I have this XAML. If I remove the StackPanel.Resources section I get the styles that were defined at the application level. If I leave it in, then I only get the new styles.

How to I make it combine both the local and global styles?

<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="B开发者_开发技巧utton" >
                    <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>

In case it helps, this is how I defined the globla styles.

<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>


To Combine the application Level + Local Resource 

in the local resource definition

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

This will give you style from app level as well the local level

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜