在动画中更改边框背景颜色



我是XAML地区的新手,我只想了解VSM。当我在故事板中添加一些东西时,总是警告相同的错误。如下:

无法解析targetProperty背景。

<phone:PhoneApplicationPage.Resources>
    <ControlTemplate x:Key="ButtonControlTemplate1" TargetType="Button">
        <Border 
            BorderThickness="{TemplateBinding BorderThickness}"
            Height="{TemplateBinding Height}"
            Width="{TemplateBinding Width}"
            Margin="{TemplateBinding Margin}"
            Padding="{TemplateBinding Padding}"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            Name="btnBorder">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal"/>
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ColorAnimation Duration="0" 
                                            To="Blue"
                                            Storyboard.TargetName="btnBorder"
                                            Storyboard.TargetProperty="Background.Color"
                                            />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed"/>
                    <VisualState x:Name="Disabled"/>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <ContentPresenter 
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" >
            </ContentPresenter>
        </Border>
    </ControlTemplate>
</phone:PhoneApplicationPage.Resources>
<Button 
            x:Name="btnSubmit" 
            Grid.Row="3" 
            Grid.Column="0" 
            Grid.ColumnSpan="2" 
            Content="Login" 
            IsEnabled="False" 
            Click="btnSubmit_Click" 
            Margin="0" 
            BorderThickness="2"
            BorderBrush="White"
            Background="Aqua"
            Padding="15" 
            Template="{StaticResource ButtonControlTemplate1}"
            />

为什么以及如何修复它,谢谢!

您的视觉状态应为PointerOver而不是MouseOver

即使如此,ColorAnimation也对我没有任何作用。但是,这确实是:

<VisualState x:Name="PointerOver">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames
            Storyboard.TargetName="btnBorder"
            Storyboard.TargetProperty="Background">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Blue" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

注意目标属性是Background而不是Background.Color

最新更新