WPF如何强制设计器显示自定义窗口样式

WPF如何强制设计器显示自定义窗口样式,wpf,xaml,custom-controls,designer,Wpf,Xaml,Custom Controls,Designer,我根据窗口控件制作了一个新的CustomControl 当我使用控件时,它不会出现在设计器模式中,而是使用默认的窗口样式。 如何强制设计器显示我的窗口样式而不是默认样式 My Main Window.xaml: <CustomWindow:MetroWindow x:Class="Testz.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:

我根据窗口
控件制作了一个新的
CustomControl

当我使用控件时,它不会出现在设计器模式中,而是使用默认的窗口样式。
如何强制设计器显示我的窗口样式而不是默认样式

My Main Window.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>

它在设计器中的外观和实际外观:


我想我理解你想要实现的目标

问题是Visual Studio设计器找不到资源,因为它位于库中。您需要做的是在应用程序上创建一个指向它的ResourceDictionary,以便能够看到designer时间模板

<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>


您正在使用Mahapps Metro,对吗

您可以使用它提供的样式。



您可以通过将Blue.xaml的资源字典更改为其他颜色来更改窗口的颜色,只需将其签出即可。

当App.xaml中的资源引用正常时,您应该重新启动Visual Studio。在大多数情况下,主题会正确显示


关于

你的问题是什么?如何强制设计师显示“正确”的窗口样式,编辑我的帖子?你指的是设计师中“灰色”的标题栏,而不是真正的窗口吗?@Omribitan不仅如此,而且动作图标也不会显示(关闭、最大化和最小化)。如果我直接在app.xaml中使用窗口的设计,而不是作为自定义控件使用(我不想这样做,因为我还重写了函数,并且我需要这个控件是通用的),看起来还可以。你想让我上传那张照片吗?我没法让它工作。运行时是ak,但设计时显示“正常”窗口样式。
<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>