VisualState commonState doesn´t work xaml

不打扰是莪最后的温柔 提交于 2019-12-13 05:59:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!