Button 按下“使”按钮时背景变为白色

Button 按下“使”按钮时背景变为白色,button,windows-phone-8,Button,Windows Phone 8,如何使包含图像的按钮在按下时变为白色背景 默认情况下,当我按下我的按钮时,按钮中不会显示图像,并更改为手机的强调色 下面是按钮的XAML代码: <VisualState x:Name="Pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source" Storyboard.TargetName="Img">

如何使包含图像的按钮在按下时变为白色背景

默认情况下,当我按下我的按钮时,按钮中不会显示图像,并更改为手机的强调色

下面是按钮的XAML代码:

<VisualState x:Name="Pressed">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source" Storyboard.TargetName="Img">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Assets/appbar.control.play.png" />  
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Black"/>
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
            <DiscreteObjectKeyFrame KeyTime="0" Value="White"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

您需要做的是创建一个按钮模板来修改按下的视觉状态


查看答案是否对您有帮助,两个链接都有按下的视觉状态代码。

您需要将按下的视觉状态更改为:

(在这种情况下,按下按钮时背景变为红色)


//像这样设置图像路径

我添加了按钮按下的视觉状态代码,您能澄清我需要修改哪些代码吗?我完全不理解链接中的答案您可以根据需要设置value属性…如上图所示Ok,我让按钮在按下时变为白色,但如何使按钮内的图像变为黑色?Ok..更新了上面的代码和图像路径…这可以帮助解决您的问题仍然无法解决,按钮将变为白色,但不会将其中的图像高亮显示为黑色。代码更新
    <VisualState x:Name="Pressed">
        <Storyboard>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source" Storyboard.TargetName="Img">
              //Set you image path like this
                <DiscreteObjectKeyFrame KeyTime="0" Value="Assets/..." />                                                                                  
            </ObjectAnimationUsingKeyFrames>  
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                <DiscreteObjectKeyFrame KeyTime="0" Value="Red"/>
            </ObjectAnimationUsingKeyFrames>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                <DiscreteObjectKeyFrame KeyTime="0" Value="Red"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </VisualState>