首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF自定义控件-视觉设计器不支持Generic.xaml根元素

WPF自定义控件-视觉设计器不支持Generic.xaml根元素
EN

Stack Overflow用户
提问于 2014-02-25 14:37:36
回答 1查看 878关注 0票数 0

我试图自定义扩展的WPF工具包的RichTextBoxFormatBar工具,因为我想拿走一些开箱即用的功能。

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

代码语言:javascript
复制
<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,它将所有代码保存在/逻辑后面,并继承自Control.

当我试图查看Generic.xaml的设计器时,我没有得到任何设计器,并且消息“故意离开空白。文档根元素不受视觉设计者的支持”。

可能是我的xaml代码没有正确绑定到Ises.FormatBar.cs的一个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-25 23:07:58

当我试图查看Generic.xaml的设计器时,我没有得到任何设计人员,并且消息“故意离开空白”。

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

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

理想情况下,您不应该在自定义控件样式中包括“x:Key=”IsesFormatTemplate。这样就可以将其应用于所有使用,而不必显式地包含该样式。要么移除键,要么在所有使用中包括Style="{StaticResource IsesFormateTemplate}"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22017358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档