有没有办法使用可视化 XAML 设计器来创作 WPF自定义控件,就像使用用户控件一样?
据我所知,在 Visual Studio 2010 和 2012 中没有这样的东西。我也看过 Expression Blend 4,但似乎没有一个支持这一点。
我觉得这很难相信,因为在我看来这将是一个明显且必要的功能。
为了清楚起见,我正在寻找一个 XAML 编辑器,当我使用它时,我可以在其中直观地看到 XAML 的结果作为呈现的控件,就像在 Visual Studio 2010 中创作用户控件时一样。
有没有办法使用可视化 XAML 设计器来创作 WPF自定义控件,就像使用用户控件一样?
据我所知,在 Visual Studio 2010 和 2012 中没有这样的东西。我也看过 Expression Blend 4,但似乎没有一个支持这一点。
我觉得这很难相信,因为在我看来这将是一个明显且必要的功能。
为了清楚起见,我正在寻找一个 XAML 编辑器,当我使用它时,我可以在其中直观地看到 XAML 的结果作为呈现的控件,就像在 Visual Studio 2010 中创作用户控件时一样。
这是我想出的一件事:
像这样更改项目中的代码:
CustomControl1Dictionary.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary1">
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30" FontWeight="Bold">This freaking sucks!</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
主题\Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfCustomControlLibrary1;component/CustomControl1Dictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
CustomControl1View.xaml
<UserControl x:Class="WpfCustomControlLibrary1.CustomControl1View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfCustomControlLibrary1"
mc:Ignorable="d"
d:DesignHeight="292" d:DesignWidth="786">
<local:CustomControl1 />
</UserControl>
这使我可以将用户控件作为弹出窗口打开,并且在构建项目并单击用户控件设计器后,我可以看到我在自定义控件资源字典中对 XAML 所做的更改。