我的造型超链接如下:WPF控件模板继承风格从境内出现与风格“一个FooterPanel”父资源
<Style x:Key="FooterPanel" TargetType="{x:Type Border}">
<Style.Resources>
<Style TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground" Value="{StaticResource FooterPanelLinkBrush}"/>
</Style>
</Style.Resources>
</Style>
我现在也已经创建了一个样式来创建一个按钮,超链接(这样我就可以得到一个超链接属性,如ISDEFAULT和IsCancel):
<Style x:Key="LinkButton" TargetType="{x:Type Button}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
<Hyperlink Command="{TemplateBinding Command}" CommandParameter="{TemplateBinding CommandParameter}">
<Run Text="{TemplateBinding Content}"/>
</Hyperlink>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
内一个FooterPanel普通超链接收到FooterPanelLinkBrush前景,但如果我一个一个FooterPanel内使用LinkButton的,不应用该样式。有没有办法让ControlTemplate继承FooterPanel中的样式,而不是任何全局超链接样式?
编辑:
根据这个答案https://stackoverflow.com/a/9166963/2383681有特殊处理,这意味着该Hyperlink
不会收到在FooterPanel
定义的样式,因为它不是从Control
的。
我不确定我想要做什么,因此可能没有一些代码隐藏,所以我想我只是要解决这个问题,并为FooterPanelLinkButton
创建一个新的样式,并明确引用这个按钮在页脚面板中。知道这是否可能,但不这样做会很有趣。
您可以使用[BasedOn](https://msdn.microsoft.com/en-us/library/system.windows.style.basedon(v = vs.110).aspx),但这会让每个LinkButton都有footerpanel风格不只是在footerpanel内 –