首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VisualStateManager GoToState不工作

VisualStateManager GoToState不工作
EN

Stack Overflow用户
提问于 2014-12-05 04:41:25
回答 1查看 2.6K关注 0票数 2

当屏幕的方向改变时,我称之为:

代码语言:javascript
复制
        string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();

        // Trigger the Visual State Manager
        bool success = VisualStateManager.GoToState(this, CurrentViewState, true);

在我的XAML中,有一个简单的网格(位于页面层次结构的深层)

代码语言:javascript
复制
            <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Grid.Row="2">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Rectangle x:Name="rect_1" Grid.Column="0" Fill="Blue"></Rectangle>
                <Rectangle x:Name="rect_2" Grid.Column="1" Fill="Red"></Rectangle>
                <Rectangle x:Name="rect_3" Grid.Column="2" Fill="Green"></Rectangle>

                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup>
                        <VisualState x:Name="Landscape">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames
      Storyboard.TargetName="rect_1"
      Storyboard.TargetProperty="Fill">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Brown"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>

                        </VisualState>

                        <VisualState x:Name="Portrait">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames
      Storyboard.TargetName="rect_1"
      Storyboard.TargetProperty="Fill">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Orange"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>

            </Grid>

所以它是3个简单的矩形,但它们的颜色永远不会改变。所有这些都直接取自教程:http://msdn.microsoft.com/en-us/library/windows/apps/dn495655.aspx唯一的区别是我的网格不是页面的顶部元素。问题可能是,

代码语言:javascript
复制
VisualStateManager.GoToState(this, CurrentViewState, true);

就是“这个”。但是我不知道它应该是什么,不允许将它设置为网格或其中一个矩形。

代码语言:javascript
复制
        IList<VisualStateGroup> visualStateGroups = VisualStateManager.GetVisualStateGroups(this);
        int count= visualStateGroups.Count;      

计数为0。

EN

回答 1

Stack Overflow用户

发布于 2014-12-05 05:14:52

我发现: VisualStateManager必须是佩奇的直接子对象的直接子对象。

代码语言:javascript
复制
<Page>
    <Grid>
        <VisualStateManager...>
        </VisualStateManager...>

        <!-- deep in the hierarchy somewhere -->
                     <Grid>
                          <Rectangle/>
                          <Rectangle/>
                          <Rectangle/>
                     </Grid>
    </Grid>
</Page>

我尝试将其添加为Page的直接子对象,但不起作用。我完全不明白这背后的逻辑是什么。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27303644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档