VisualState commonState doesn´t work xaml

2019-08-31 02:49发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-08-31 03:22

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().

查看更多
登录 后发表回答