尝试设置Border
的背景时,出现以下异常:
Cannot resolve TargetProperty (Border.Background).(SolidColorBrush.Color) on specified object.
您可以使用以下Xaml轻松复制此内容:
<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="LinkStyle" TargetType="HyperlinkButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="HyperlinkButton">
<Grid x:Name="ButtonGrid" Cursor="{TemplateBinding Cursor}" Background="Transparent">
<Border x:Name="ButtonBorder" CornerRadius="10 10 0 0">
<ContentControl x:Name="LinkContent" Content="{TemplateBinding Content}"/>
</Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LinkStates">
<VisualState x:Name="ActiveLink">
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonBorder" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#6F666ECC" Duration="0:0:0" />
<ColorAnimation Storyboard.TargetName="LinkContent" Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" To="#FFFFFFFF" Duration="0:0:0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<HyperlinkButton x:Name="TheLink" Content="Click" Style="{StaticResource LinkStyle}" />
</Grid>
</UserControl>
将它放在构造函数中进行测试:
TheLink.Click += (s, e) => VisualStateManager.GoToState((HyperlinkButton)s, "ActiveLink", true);
对我做错了什么的任何想法?当我在评论中放置ButtonBorder的ColorAnimation行时,它将起作用。因此,它无法找到/设置Background
的{{1}}属性,但Border
确实有Border
属性,不是吗?
答案 0 :(得分:4)
问题是Background
属性未设置为SolidColorBrush
的实例。
将以下内容添加到Border
应该可以解决问题:
<Border.Background>
<SolidColorBrush />
</Border.Background>