【问题标题】:Can't set Border Background in Silverlight StoryBoard ColorAnimation无法在 Silverlight StoryBoard ColorAnimation 中设置边框背景
【发布时间】:2012-08-10 15:32:27
【问题描述】:

尝试设置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 行放在注释中时,它将起作用。所以它很难找到/设置Border 的Background 属性,但是Border 确实有Background 属性,不是吗?

【问题讨论】:

    标签: silverlight background storyboard border coloranimation


    【解决方案1】:

    问题在于Background 属性未设置为SolidColorBrush 的实例。

    将以下内容添加到Border 应该可以解决问题:

    <Border.Background>
        <SolidColorBrush />
    </Border.Background>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      • 1970-01-01
      • 2013-03-01
      相关资源
      最近更新 更多