【发布时间】:2013-09-16 00:07:00
【问题描述】:
我正在尝试像在此处回答中所说的那样创建链接按钮:How do I make a WPF button look like a link?
- 我创建了 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>
但是我遇到了错误
“内容”属性只能设置一次。
我做错了什么?
【问题讨论】: