Here is the App.xaml:
<Application>
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Window">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
I also have the MainWindow.xaml. When viewed in Design mode in VS, it's background is, indeed, gray, as it should be. Anyway, when application is running, the window's background is default white.
Why?
How to fix this? I want all windows to have the standard background by default.
Following up on the answer from CodeNaked, you'll have to create a Style
for every Window
you have, but you can use the same style for all of them with BasedOn
like this
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Window">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Style>
<Style TargetType="{x:Type local:MainWindow}"
BasedOn="{StaticResource {x:Type Window}}"/>
<Style TargetType="{x:Type local:SomeOtherWindow}"
BasedOn="{StaticResource {x:Type Window}}"/>
<!-- Add more Windows here... -->
</ResourceDictionary>
</Application.Resources
The problem is during runtime, the type of your window will be MainWindow
, not Window
. Implicit Styles are not applied to derived types of the TargetType. So your Style won't be applied.
During design time, you are designing your MainWindow
, but I suspect it creates a Window
as the basis.
You'd need to change the type to match your window's type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With