Wednesday, 11 September 2013

How to create WPF ControlTemplate

How to create WPF ControlTemplate

Hi guys I am trying to create linkbutttonlike like said in answer here:
How do I make a WPF button look like a link?
1) I did created UserControl, default xaml looking like that:
<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>
2) I placed ControlTemplate inside
<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">
<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>
But getting error The property "Content" can only be set once.
Looks like I ma doing something wrong?

No comments:

Post a Comment