Specifying custom window appearance in WPF?

I would like to create a library of some of my commonly used WPF controls, and one of these controls is one CustomWindowthat inherits from the class Window. How can I make my CustomWindowuse the default look that is defined in the library with it?

I can replace

<Window x:Class="..." />

with

<MyControls:CustomWindow x:Class="..." />

and it works for window behavior, but does not appear.

EDIT

Here is a simplified version of what I still have:

User window control. Located in the management library.

public class CustomChromeWindow: Window
{
    static CustomChromeWindow()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomChromeWindow), 
            new FrameworkPropertyMetadata(typeof(CustomChromeWindow)));
    } 
}

Window style. Located in Generic.xaml, ResourceDictionary in the Themes folder in the management library

<Style TargetType="local:CustomChromeWindow">
    <Setter Property="WindowStyle" Value="None" />
    <Setter Property="Background" Value="Red" />
</Style>

test window. Launches a separate project window that references a management library

<local:CustomChromeWindow
    x:Class="MyControlsTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyControls;assembly=MyControls"
    Title="MainWindow" Height="350" Width="525"
    >
    <Grid>
        <TextBlock Text="This is a Test" />
    </Grid>
</local:CustomChromeWindow>

WindowStyle .

+5
3

xaml:

<Window x:Class="MyNamespace.CustomWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:MyControls="MyNamespace">

    <Window.Style>
        <Style TargetType="MyControls:CustomWindow">
        ...
        </Style>
    </Window.Style>

    <ContentPresenter />

</Window>

. , ( )\Themes\Generic.xaml :

<Style TargetType="{x:Type MyControls:CustomWindow}">
    <Setter Property="WindowStyle" Value="None" />
    <Setter Property="AllowsTransparency" Value="True" />
    ...

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type MyControls:CustomWindow}">
                <Border>
                    ...
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
+2

AssemblyInfo.cs

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
    //(used if a resource is not found in the page, 
    // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries)
)]
+1

( Cctor ):

 DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomWindow)
                                             , new FrameworkPropertyMetadata(typeof(CustomWindow)));`
0

All Articles