基于样式的基础不使用基础 [英] Style BasedOn not using Base
本文介绍了基于样式的基础不使用基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
我正在尝试根据另一种样式创建样式,但是我的问题是,未按某种方式绘制基础.这是XAML:
Hello
I'm trying to create a style based on another style but my problem is, the base is somehow not drawn. Here's the XAML:
<Style x:Key="ControlBaseStyle" TargetType="{x:Type modulesbase:ControlBase}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type modulesbase:ControlBase}">
<DockPanel LastChildFill="True">
<Border DockPanel.Dock="Top" Background="{DynamicResource MyToolBarBlueGradientBrush}" VerticalAlignment="Top" Height="20">
<TextBlock TextWrapping="NoWrap" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Margin="4,0,0,0">
<TextBlock.Text>
<Binding Path="Caption" Mode="OneWay">
<Binding.RelativeSource>
<RelativeSource Mode="FindAncestor" AncestorType="{x:Type modulesbase:ControlBase}" />
</Binding.RelativeSource>
</Binding>
</TextBlock.Text>
</TextBlock>
</Border>
<ContentPresenter/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="FormBaseStyle" TargetType="{x:Type modulesbase:FormBase}" BasedOn="{StaticResource ControlBaseStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type modulesbase:FormBase}">
<DockPanel LastChildFill="True">
<Button Name="btnSave" DockPanel.Dock="Bottom" Content="Speichern" Width="75" HorizontalAlignment="Right"></Button>
<ContentPresenter/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在发生的事情是,我将UserControl的样式设置为FormBaseStyle,仅绘制了Button,但未绘制在ControlBaseStyle中定义的边框.
有什么想法吗?
Now what happens is, I set the style of my UserControl to FormBaseStyle and only the Button is drawn, but not the border that I defined in ControlBaseStyle.
Any ideas?
推荐答案
您好,NoRyp,
显示了正确的ControlTemplate!您的UserControl来自modulesmodule:FormBase类型,否则您无法为其分配FormBaseStyle.
Hi NoRyp,
the correct ControlTemplate was shown! Your UserControl is from type modulesbase:FormBase otherwise you could not assign the FormBaseStyle to it.
这篇关于基于样式的基础不使用基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文