问题
I have this XAML view. The VisualStateGroups
for the visual triggers
works fine, but the VisualStateGroup
for the common states doesn't.
I try assign to a rectangle in the beginning and then neither work. In other views this works fine .. :(
<view:NavigationStoredPage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/ResponsiveStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</view:NavigationStoredPage.Resources>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="rer">
<DiscreteObjectKeyFrame KeyTime="0" Value="#121212"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="rer">
<DiscreteObjectKeyFrame KeyTime="0" Value="#121212"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle Fill="Red" x:Name="rer" Width="100" Height="100" HorizontalAlignment="Left" Canvas.ZIndex="99" VerticalAlignment="Top" />
回答1:
Your code actually has to transition to one of these CommonStates
using VisualStateManager.GoToState()
for the state to transition. It happens automatically for a control like Button
because somewhere in the Button
class or its base class - there is a call to GoToState()
.
来源:https://stackoverflow.com/questions/32912308/visualstate-commonstate-doesn%c2%b4t-work-xaml