【发布时间】:2016-03-05 22:25:25
【问题描述】:
我有一个从自定义窗口继承的 WPF 窗口。它运行正常,但 VS 设计器将其显示为默认的空窗口。
自定义窗口代码:
using System.Windows;
using System.Windows.Media;
namespace WpfApplication2
{
public class CustomWindow : Window
{
public CustomWindow()
{
Background = new SolidColorBrush(Colors.Red);
}
}
}
MainWindow.xaml:
<local:CustomWindow x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
Title="MainWindow" Height="350" Width="525">
</local:CustomWindow>
设计师:
预期结果:
【问题讨论】:
-
你不见了
InitializeComponent() -
没有这样的功能,因为
CustomWindow类不包含 XAML。而且无论如何也不可能从包含 XAML 标记的 Windows 继承类。 -
VS 的版本/构建是什么?什么版本的 Windows?
-
VS 2015(标签中提到),Windows 10(应该没关系)
-
我确信这是 XAML 设计器的错误/限制。我尝试了所有我知道的方法来设置子类背景(C#、XAML、Themes\Generic.xaml)。所有在运行时工作。在设计时没有。 MahApps.Metro 是一个主题库。他们继承了Window,他们遇到了这个问题(我和作者聊天)。
标签: c# wpf xaml visual-studio-2015