tags:

views:

63

answers:

1

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

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>
+1  A: 
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

Kishore Kumar
What if the application level style doesn't have a name?
Jonathan Allen
you just give the BaseTypeName like "TextBlock"
Kishore Kumar
Do you mean like <Style TargetType="Button" BasedOn="{StaticResource Button}" >, 'cause that's not compiling.
Jonathan Allen
BasedOn="{StaticResource {x:Type Button}}"
Kishore Kumar
That was it, thanks.
Jonathan Allen