tags:

views:

1033

answers:

1

I am setting a style for the Window in the App.xaml like such:

<Application x:Class="MusicRepo_Importer.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" StartupUri="TestMaster.xaml">
    <Application.Resources>

        <Style TargetType="Window">
            <Setter Property="WindowStyle" Value="None"></Setter>
        </Style>

    </Application.Resources>
</Application>

With which I basically want every Window to have its WindowStyle's property value set to None (to remove the default windows frame and border); But it is not working.

What am I missing here?

+3  A: 

I believe you have to name the style and apply it to each window like the following..

In app.xaml/resources..

<Style x:Key="MyWindowStyle" TargetType="Window">
    <Setter Property="WindowStyle" Value="None"></Setter>
</Style>

Then in the window.xaml..

<Window x:Class="MusicRepo_Importer.MyWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="MyStyledWindow" Style="{StaticResource MyWindowStyle}">

This should work, but simply applying the style with TargetType for Window in the resource won't force the Window to use that style although it seems to work for other elements.

Edit:
Found some info in relation to applying default styles to a window element..

If you supply a TargetType, all instances of that type will have the style applied. However derived types will not... it seems. <Style TargetType="{x:Type Window}"> will not work for all your custom derivations/windows. <Style TargetType="{x:Type local:MyWindow}"> will apply to only MyWindow. So the options are

Use a Keyed Style that you specify as the Style property of every window you want to apply the style. The designer will show the styled window.

From the Question: How to set default WPF Window Style in app.xaml?

The person who answered the question had a interesting idea about inheriting from a base window that has the style applied.

Quintin Robinson
Thanks for the insight
Andreas Grech