1

の背景を設定しようとすると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したがって、のプロパティを検索/設定するのに問題BorderBorderありますが、Backgroundプロパティはありますか?

4

1 に答える 1

4

問題は、Backgroundプロパティがのインスタンスに設定されていないことですSolidColorBrush

に以下を追加するとBorder、トリックが実行されます。

<Border.Background>
    <SolidColorBrush />
</Border.Background>
于 2012-08-10T16:45:58.137 に答える