2016-06-14 58 views
0

我嘗試使用visual sate manager更改按鈕前景色,但它根本不起作用。在uwp中使用VisualStateManager更改按鈕前景

<Button x:Name="Close" HorizontalAlignment="Stretch" 
              Width="100" Background="#FF4F4F4F" 
              Height="50" BorderThickness="2" BorderBrush="#FF2F2F2F" 
              Content="Cancel"> 
             <VisualStateManager.VisualStateGroups> 
              <VisualStateGroup x:Name="CommonStates"> 
               <VisualState x:Name="PointerOver"> 
                <Storyboard> 
                 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Close" 
                    Storyboard.TargetProperty="Foreground"> 
                  <DiscreteObjectKeyFrame KeyTime="0" Value="#FFFFFFFF" /> 
                 </ObjectAnimationUsingKeyFrames> 
                </Storyboard> 
               </VisualState> 
               <VisualState x:Name="Pressed"> 
                <Storyboard> 
                 <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Close" 
                    Storyboard.TargetProperty="Foreground"> 
                  <DiscreteObjectKeyFrame KeyTime="0" Value="#FFFFFFFF" /> 
                 </ObjectAnimationUsingKeyFrames> 
                </Storyboard> 
               </VisualState> 
              </VisualStateGroup> 
             </VisualStateManager.VisualStateGroups> 
            </Button> 

請幫我這個工作。

在此先感謝。

+1

請問如果在控件模板做它,而不是它的工作? – Gui

回答

1

它不工作,因爲您試圖爲畫筆類型設置顏色值。

請使用您需要的顏色創建一個Brush StaticResource。並在動畫中設置資源。

<SolidColorBrush x:Key="TextBoxErrorThemeBrush" Color="Red" /> 

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PART_TextBlock"> 
    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxErrorThemeBrush}"/> 
</ObjectAnimationUsingKeyFrames> 

問候,

傑西