有没有一种方法可视化编辑WPF自定义控件?
有没有办法像使用用户控件一样使用可视化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所做的更改。
链接地址: http://www.djcxy.com/p/61313.html