我正在尝试像在此处回答中所说的那样创建链接按钮:如何使 WPF 按钮看起来像链接?
- 我创建了 UserControl,默认的 xaml 看起来像这样:
<UserControl x:Class="Wpf.Controls.HyperlinkLikeButtonTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
我放在
ControlTemplate
里面:<ControlTemplate x:Key="HyperlinkLikeButtonTemplate" TargetType="{x:Type Button}"> <TextBlock x:Name="innerText" Foreground="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}" Cursor="Hand" > <ContentPresenter /> </TextBlock> <ControlTemplate.Triggers> <Trigger Property="Button.IsMouseOver" Value="true"> <Setter TargetName="innerText" Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /> <Setter TargetName="innerText" Property="TextDecorations" Value="Underline" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style x:Key="HyperlinkLikeButton" TargetType="{x:Type Button}"> <Setter Property="Template" Value="{StaticResource HyperlinkLikeButtonTemplate}" /> </Style>
但我收到错误
“内容”属性只能设置一次。
我做错了什么?