C# WPF自定义控件-visual designer不支持Generic.xaml根元素

C# WPF自定义控件-visual designer不支持Generic.xaml根元素,c#,wpf,xaml,generics,C#,Wpf,Xaml,Generics,我试图定制扩展WPF工具包的RichTextBoxFormatBar工具,因为我想去掉一些现成的功能 我创建了一个自定义控件,并将原始工具源代码复制到Themes\Generic.xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local

我试图定制扩展WPF工具包的
RichTextBoxFormatBar
工具,因为我想去掉一些现成的功能

我创建了一个自定义控件,并将原始工具源代码复制到
Themes\Generic.xaml

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters;assembly=Xceed.Wpf.Toolkit" 
xmlns:MyNamespace="clr-namespace:IsesTextEditor">

<conv:ColorToSolidColorBrushConverter x:Key="ColorToSolidColorBrushConverter" />

<ControlTemplate TargetType="{x:Type MyNamespace:IsesFormatBar}" x:Key="IsesFormatTemplate">
    <Border Background="Transparent"
          Cursor="Hand"
          ToolTip="Click to Drag">
        <StackPanel VerticalAlignment="Center"
                 Width="75">
            <Line SnapsToDevicePixels="True"
              Stretch="Fill"
              StrokeDashArray="1,2"
              StrokeThickness="1"
              X1="0"
              X2="1"
              Margin=".5">
                <Line.Stroke>
                    <SolidColorBrush Color="Gray" />
                </Line.Stroke>
            </Line>
            <Line SnapsToDevicePixels="True"
              Stretch="Fill"
              StrokeDashArray="1,2"
              StrokeThickness="1"
              X1="0"
              X2="1"
              Margin=".5">
                <Line.Stroke>
                    <SolidColorBrush Color="Gray" />
                </Line.Stroke>
            </Line>
            <Line SnapsToDevicePixels="True"
              Stretch="Fill"
              StrokeDashArray="1,2"
              StrokeThickness="1"
              X1="0"
              X2="1"
              Margin=".5">
                <Line.Stroke>
                    <SolidColorBrush Color="Gray" />
                </Line.Stroke>
            </Line>
        </StackPanel>
    </Border>
</ControlTemplate>

design blah blah design


                </StackPanel>

            </StackPanel>
        </Grid>
    </Border>
</ControlTemplate>

<!-- =================================================================== -->
<!-- Style                                                               -->
<!-- =================================================================== -->
<Style TargetType="{x:Type MyNamespace:IsesFormatBar}">
    <Setter Property="Template"
          Value="{StaticResource richTextBoxFormatBarTemplate}" />
    <Setter Property="Effect">
        <Setter.Value>
            <DropShadowEffect BlurRadius="5"
                          Opacity=".25" />
        </Setter.Value>
    </Setter>
    <Setter Property="Background"
          Value="Transparent" />
    <Setter Property="IsTabStop"
          Value="false" />
</Style>

设计废话

对不起,很多Xaml

我有
Ises.FormatBar.cs
,它将我所有的代码隐藏在/logic后面,并从
控件继承。

当我试图查看
Generic.xaml的设计器时,我没有看到设计器,消息“故意留空”。可视化设计器不支持文档根元素。'

可能是因为我的xaml代码没有正确绑定到
Ises.FormatBar.cs

当我试图查看Generic.xaml的设计器时,我没有得到任何设计器和 消息“故意留白”

这很好。这是因为您试图在设计器中查看ResourceDictionary

这是唯一的问题吗? 我还猜测,当您将此自定义控件用于其他用户控件时,您将无法看到预期的视图

理想情况下,您不应该在自定义控件样式中包含“x:Key=“IsesFormatTemplate”。这样它就可以应用于所有用法,而不必显式包含样式。请删除该键,或者在所有用法中包含
style=“{StaticResource IsesFormatTemplate}”