Search code examples
c#wpfxamlresourcedictionary

WPF Style based on ResourceDictionary in App.xaml


I use a style-preset which is defined in a ResourceDictionary in my App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

What i want now is to be able to set a new style in another xaml which shouldn't override the settings of my App.xaml.

This should then look similar like that:

<Grid.Resources>
    <Style TargetType="Button" BasedOn=".....">
        <Setter Property="Margin" Value="0,0,5,0"></Setter>
    </Style>
</Grid.Resources>

Problem is that i can't figure out what i need to write in the BasedOn element.

Can someone show me an easy way how to do that please?


Solution

  • Try this if you want to base your style on the default Button style:

    <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
    ...