我将尝试按照这里的回答创建类似链接按钮: 如何使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>
I placed
ControlTemplate
inside:<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>
但是我遇到了错误
属性“内容”只能设置一次。
我做错了什么?
<UserControl.Resources>
没有关闭。 - Sreginogemoh