簡體   English   中英

WPF自定義控件-可視設計器不支持Generic.xaml根元素

[英]WPF Custom Control- Generic.xaml root element not supported by visual designer

我想自定義擴展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后面並從Control.繼承Control.

當我嘗試查看Generic.xaml的設計器時,沒有得到設計器,並且消息“故意留空”。 視覺設計器不支持文檔根元素。

我的xaml代碼未正確綁定到Ises.FormatBar.cs可能是一個問題?

當我嘗試查看Generic.xaml的設計器時,沒有得到設計器,並且消息“故意留空”。

這可以。 這是因為您試圖在設計器中查看ResourceDictionary。

那是唯一的問題嗎? 我還會猜測,當您將此自定義控件用於其他一些用戶控件時,您將無法看到預期的視圖。

理想情況下,您不應在自定義控件樣式中包含“ x:Key =“ IsesFormatTemplate”。因此,無需明確包含樣式即可將其應用於所有用法。要么刪除鍵,要么包含Style="{StaticResource IsesFormateTemplate}"中的所有用法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM