1

ユーザー コントロールと同じように、ビジュアル XAML デザイナーを使用して WPFカスタム コントロールを作成する方法はありますか?

私が見る限り、Visual Studio 2010 と 2012 にはこのようなものはありません。Expression Blend 4 も調べましたが、どれもこれをサポートしていないようです。

これは明らかで必要な機能であるように思われるため、これは信じがたいことです。

明確にするために、Visual Studio 2010 でユーザー コントロールを作成するときとまったく同じように、XAML の結果をレンダリングされたコントロールとして視覚的に確認できる XAML エディターを探しています。

4

1 に答える 1

1

これが私が思いついた1つのことです:

  1. Visual Studio 2010 で、新しい WPF カスタム コントロール プロジェクトを作成します。
  2. CustomControl1Dictionary.xamlという新しいリソース ディクショナリを追加します。
  3. CustomControl1View.xamlという新しいユーザー コントロールを追加します。
  4. プロジェクトのコードを次のように変更します。

    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 への変更を確認できます。

于 2012-11-13T17:14:46.737 に答える