2012-08-10 61 views
1

當試圖設置Border的背景下,我得到以下異常:無法設置邊框背景Silverlight中的故事板ColorAnimation

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屬性Border,但Border確實有Background屬性,不是嗎?

回答

4

問題是Background屬性未設置爲SolidColorBrush的實例。

添加以下到Border應該做的伎倆:

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