2011-09-21 70 views
0

我下面的樣式設置爲一個按鈕的風格:問題在設置一個按鈕

<Style x:Key="CustomButtonStyle1" TargetType="Button"> 
      <Setter Property="Background" Value="Transparent"/> 
      <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/> 
      <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> 
      <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> 
      <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/> 
      <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
      <Setter Property="Padding" Value="10,3,10,5"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="Button"> 
         <Grid Background="Transparent"> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup x:Name="CommonStates"> 
            <VisualState x:Name="Normal"/> 
            <VisualState x:Name="MouseOver"/> 
            <VisualState x:Name="Pressed" /> 
            <VisualState x:Name="Disabled"/> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="White"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground"> 
               <DiscreteObjectKeyFrame KeyTime="0"> 
                <DiscreteObjectKeyFrame.Value> 
                 <ImageBrush ImageSource="Images/aaa2.png"/> 
                </DiscreteObjectKeyFrame.Value> 
               </DiscreteObjectKeyFrame> 
              </ObjectAnimationUsingKeyFrames> 
             </Storyboard> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
          <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}"> 
           <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
          </Border> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

但是我得到了下面的錯誤,我不知道如何解決:

錯誤1無法將類型'System.Windows.Media.Animation.Storyboard'的實例添加到'MS.Internal。!VisualStateCollection'類型的集合中。 [行:23的位置:17]

該按鈕定義如下:

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,30,0,0"> 
       <Button Name="aaa" Width="200" Content="aaa" Margin="0,0,-10,0" Click="aaa_Click" BorderThickness="0" BorderBrush="{x:Null}" Height="91" Foreground="Black" Style="{StaticResource CustomButtonStyle1}"> 
        <Button.Background> 
         <ImageBrush ImageSource="../Images/aaa.png"/> 
        </Button.Background> 
       </Button> 

回答

0

的故事板應該是一個的VisualState內部。

<VisualState x:Name="Pressed"> 
<Storyboard>...</Storyboard> 
</VisualState> 
+1

ahhhh傻我,謝謝哥們:) – Ameen