1

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?

Martin Niederl
  • 649
  • 14
  • 32

1 Answers1

3

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

<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
...
mm8
  • 163,881
  • 10
  • 57
  • 88
  • is a default style always the style which i set on top of that new style? and btw it works fine – Martin Niederl Jun 01 '17 at 21:46
  • 1
    The default style is in this case the style that is being applied to the Buttons in scope before you define the above style, i.e. the style defined in the ResourceDictionary that you have merged in your App.xaml. You base the new style on this one. – mm8 Jun 01 '17 at 21:49
  • 1
    Ok didn't know it will be that easy. Yes i couldn't accept because i had a 5 min cooldown before. – Martin Niederl Jun 01 '17 at 22:26