0

Well I am trying to create some custom look and feel for my application without creating an entire theme. I've create a WPF 4.5 Application with a default Window and the following App.xaml

<Application x:Class="WpfBGTest.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources> 
            <Style TargetType="Window">
                <Setter Property="Background" Value="Yellow" />
            </Style>

    </Application.Resources>
</Application>

And the entirely default window code

<Window x:Class="WpfBGTest.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">

    <Grid>
    </Grid>
</Window>

By doing this I see that in Design Time my Window.xaml is yellow. But running the application the Window loses its yellow color and goes back to grey (current windows theme?)

What happens here? How can I customize my application without putting explicit StaticResource Markups on every control? My Style has a target type and no key. I do not understand why design time differs that much from runtime.

I've read enough about the issue with merged dictionaries but the code above is basically a vanilla WPF App with one style.

Edit: I've used Snoop to see that DefaultStyle is used when deciding what background will be fetched. But why? Watching the Dependecy Property precedence list: http://msdn.microsoft.com/en-us/library/ms743230.aspx my Application Style should be picked just before the default style

Samuel
  • 6,126
  • 35
  • 70
  • 1
    Possible duplicate of http://stackoverflow.com/questions/4279773/wpf-window-style-not-being-applied – brader24 Aug 14 '13 at 17:30

1 Answers1

1

Ok, by reading the post below brader24's link is correct. This is a derived type issue like you cannot set Foreground on Control, you cannot set Background on Window as it is not propagated down to my specific window

Solution post: https://stackoverflow.com/a/6902225/2416394

Edit: This is solved for me. I'll mark it resolved as soon as I am able to.

Community
  • 1
  • 1
Samuel
  • 6,126
  • 35
  • 70