WPF how to make a designer display a custom window style

I created a new CustomControl based on the Control window.
When I use my control, it does not appear in design mode, instead, it still uses the default window style.
How to make the designer display my window style instead of the standard 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 entire project - you may need it

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

enter image description here

+7
wpf xaml custom-controls designer
source share
3 answers

I think I understand what you are trying to accomplish.

The problem is that Visual Studio Designer cannot find the resource because it is in the library. What you need to do is create a ResourceDictionary pointing to it on your application in order 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 the links below.

OnApplyTemplate () is never called

WPF get development time type?

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

+6
source share

You are using Mahapps Metro, right?

You can use the styles he created. Styling a window with Metro

 <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> 

You can change the color of the window by changing the Blue.xaml resource dictionary with other colors, just check it.

0
source share

When the resource links in App.xaml are fine, you must restart Visual Studio. In most cases, topics are displayed correctly.

Hi

0
source share

All Articles