I've created a WPF application using Visual Studio 2010, converted App.xaml to a Page and added a call to InitializeComponent in the constructor. I've then created a new window called "LoginWindow" and added the following to the App.xaml.cs:
[STAThread]
public static void Main()
{
var app = new App();
app.Run(new LoginWindow());
}
Next I added a style to the App.xaml as follows:
<Style x:Key="MyWindowStyle" TargetType="Window">
<Setter Property="Background" Value="Red" />
</Style>
Finally, in the LoginWindow I added the following style reference:
Style="{StaticResource MyWindowStyle}"
When I run the program I see my login window with a red background as expected. However, when I view the window in the designer the style is not applied. The {StaticResource MyWindowStyle} is underline and showing the error, "The resource 'MyWindowStyle' could not be resolved".
Why is this?
EDIT
I got a fix on another question that sorted this one out too. I stopped the app.xaml being a page and used the StartUp even instead of a Main method.