我有这个xaml
<Button.Content>
<Hyperlink>
<Hyperlink.TextDecorations>
<TextDecoration>
<TextDecoration.Pen>
<Pen Thickness="0" />
</TextDecoration.Pen>
</TextDecoration>
</Hyperlink.TextDecorations>
<Run Text="jumped over" />
</Hyperlink>
</Button.Content>
我需要从样式中应用它。我的风格是这样的
<Style x:Key="Button_Link" TargetType="{x:Type Hyperlink}">
<Setter Property="TextDecorations" >
<Setter.Value>
<TextDecorations>
<TextDecoration>
<TextDecoration.Pen>
<Pen Thickness="0" />
</TextDecoration.Pen>
</TextDecoration>
</TextDecorations>
</Setter.Value>
</Setter>
</Style>
这导致我的样式文件出现错误,该文件是用于松散 XAML 的 ResourceDictionary
我正在将样式应用到像这样的超链接
Style="{DynamicResource Button_Link}"
最佳答案
您不需要将笔粗细设置为零来删除下划线,您可以使用以下样式:
<Style x:Key="Button_Link" TargetType="{x:Type Hyperlink}">
<Setter Property="TextDecorations" Value="None" />
</Style>
如果这只是一个简化的示例,您可以通过替换 <TextDecorations>
来修复现有样式。与 <TextDecorationsCollection>
像这样:
<Style x:Key="Button_Link" TargetType="{x:Type Hyperlink}">
<Setter Property="TextDecorations">
<Setter.Value>
<TextDecorationCollection>
<TextDecoration>
<TextDecoration.Pen>
<Pen Thickness="0" />
</TextDecoration.Pen>
</TextDecoration>
</TextDecorationCollection>
</Setter.Value>
</Setter>
</Style>
此外,虽然不需要,但您的样式是静态的,因此可以像
一样应用Style="{StaticResource Button_Link}"
关于c# - 如何通过 WPF 的 XAML 中的样式应用超链接 TextDecorations 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8742045/