我试图自定义扩展的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,它将所有代码保存在/逻辑后面,并继承自Control.
当我试图查看Generic.xaml的设计器时,我没有得到任何设计器,并且消息“故意离开空白。文档根元素不受视觉设计者的支持”。
可能是我的xaml代码没有正确绑定到Ises.FormatBar.cs的一个问题。
发布于 2014-02-25 23:07:58
当我试图查看Generic.xaml的设计器时,我没有得到任何设计人员,并且消息“故意离开空白”。
这很好。这是因为您试图在设计器中查看ResourceDictionary。
这是唯一的问题吗?我还会猜测,当您将这个自定义控件使用到其他用户控件中时,您将无法看到预期的视图。
理想情况下,您不应该在自定义控件样式中包括“x:Key=”IsesFormatTemplate。这样就可以将其应用于所有使用,而不必显式地包含该样式。要么移除键,要么在所有使用中包括Style="{StaticResource IsesFormateTemplate}"。
https://stackoverflow.com/questions/22017358
复制相似问题