VisualState commonState 不起作用 xaml [英] VisualState commonState doesn´t work xaml

查看:25
本文介绍了VisualState commonState 不起作用 xaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 XAML 视图.视觉触发器的 VisualStateGroups工作正常,但常见状态的 VisualStateGroup 没有.

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" />

推荐答案

您的代码实际上必须使用 VisualStateManager.GoToState() 转换到这些 CommonStates 之一作为状态过渡.对于像 Button 这样的控件,它会自动发生,因为在 Button 类或其基类中的某处 - 调用了 GoToState().

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

这篇关于VisualState commonState 不起作用 xaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆