Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Custom Window Control in Visual Studio Design View

$
0
0

I've created a custom control that inherits from the standard Window control.  The control works great when the application is run, but does not display correctly in the Visual Studio design window.  The window displayed is simply the standard control. I've had no problems with other custom controls displaying incorrectly. Any ideas? 

Edit:

Here is how to recreate a simplified version of the problem I'm having. 

1. Create a new WPF Project in Visual Studio 2013.

2. Add a custom control:

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

3.  Edit the default template in Themes/Generic.xaml:

<Style TargetType="{x:Type local:CustomWindow}"><Setter Property="WindowStyle" Value="None"/><Setter Property="ResizeMode" Value="NoResize"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type local:CustomWindow}"><Border Background="Blue"
                            BorderBrush="Yellow"
                            BorderThickness="50"><AdornerDecorator><ContentPresenter/></AdornerDecorator></Border></ControlTemplate></Setter.Value></Setter></Style>

4. Change the MainWindow to the new CustomWindow control:

<local:CustomWindow x:Class="WpfApplication3.MainWindow"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:WpfApplication3"
              Title="MainWindow" Height="350" Width="525"><Grid/></local:CustomWindow>
public partial class MainWindow : CustomWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
Now after rebuilding and reopening the designer, the designer still shows the default window control.  This makes it difficult to design in a custom window, as the size of the window can vary from the default control.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>