I have a class named MyWindow
that derives from Window
:
using System.Windows;
public class MyWindow : Window
{
}
And I use that class in MainWindow.xaml
:
<MyWpfApp:MyWindow x:Class="MyWpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfApplication1="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock Text="Test" Foreground="Orange"/>
</Grid>
</MyWpfApp:MyWindow>
And in the App.xaml
file, I add the following style to override the Background
property of all MyWindow
instances:
<Application.Resources>
<Style TargetType="MyWpfApp:MyWindow">
<Setter Property="Background" Value="Black"></Setter>
</Style>
</Application.Resources>
But this doesn't change anything at all. No style is applied to MainWindow
.
What should I do so that I can use a global style for all MyWindow
s?
P.S.: I checked out "Modern UI"s code, I saw that they apply something like the following in their window's constructor:
using System.Windows;
public class MyWindow : Window
{
public MyWindow()
{
DefaultSyleKey = typeof (MyWindow);
}
}
But if I do this, MainWindow ends up being completely black in the content area. I am guessing that somehow its Template
property gets overriden, but I don't understand how, and how to make this work.