Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF how to force designer to display custom window style

I made a new CustomControl based on the Window Control.
When I use my Control it doesn't appear in the designer mode, instead it still uses the default window style.
How can I force the designer to display my window style instead of the default one?

My MainWindow.xaml:

<CustomWindow:MetroWindow x:Class="Testz.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:CustomWindow="clr-namespace:MetroWindow;assembly=MetroWindow"
        Title="MainWindow" Height="350" Width="525" BorderBrush="Red">
    <Grid>

    </Grid>
</CustomWindow:MetroWindow>

Link to my whole project - maybe you'll need it

How it looks in the designer and how it really looks:

enter image description here

like image 290
Ron Avatar asked Oct 18 '13 14:10

Ron


1 Answers

I think I understood what you was trying to accomplish.

The problem is that the Visual Studio Designer can't find the Resource because it is on the library. What you need to do is to create a ResourceDictionary pointing to it on you Application to be able to see the designer time template.

<Application x:Class="DemoMetroWindow.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:MetroWindow"
             StartupUri="DemoWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:/MetroWindow;component/Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

You can learn more from links bellow.

OnApplyTemplate() never being called

WPF get Type in Design time?

http://blogs.msdn.com/b/jgalasyn/archive/2007/10/29/troubleshooting-wpf-designer-load-failures.aspx

http://blogs.msdn.com/b/jnak/archive/2007/11/08/code-behind-and-the-wpf-designer.aspx

like image 70
Luiz Felipe Avatar answered Oct 14 '22 22:10

Luiz Felipe