我是XAML领域的新手,我只是想了解VSM。当我在StoryBoard中添加一些东西时,总会发出相同的错误警告。如下:
无法在指定对象上解析TargetProperty Background.Color。
<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}"
/>
为什么以及如何修复它,谢谢!
答案 0 :(得分:2)
您的视觉状态应为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
。