1
我想在WPF中开始构建自定义窗口。我认为我已经有了所有的起始部分,但到目前为止,我所得到的只是一个黑色内容的常规窗口。我认为这是因为它不会将我的模板识别为控件的默认模板。
你能让我知道我错过了什么吗?这里是我的代码:
WPF - 自定义窗口不工作
namespace BaseWindowLibrary
{
public class BaseWindow: Window
{
public BaseWindow()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(BaseWindow),
new FrameworkPropertyMetadata(
typeof(BaseWindow)));
}
}
}
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:BaseWindowLibrary">
<ControlTemplate x:Key="BaseWindowTemplate" TargetType="{x:Type base:BaseWindow}">
<Border BorderBrush="Blue" BorderThickness="3" Background="Coral" Width="100" Height="100"/>
</ControlTemplate>
<Style TargetType="{x:Type base:BaseWindow}">
<Setter Property="Template" Value="{StaticResource BaseWindowTemplate}"/>
</Style>
</ResourceDictionary>
上面的xaml代码是xaml文件的全部内容。我没有Generic.xaml。我没有默认的样式了吗? (