VisualStateManager GoToState不起作用

SPQ*_*QR3 2 c# xaml visualstatemanager winrt-xaml windows-store-apps

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

        string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();

        // Trigger the Visual State Manager
        bool success = VisualStateManager.GoToState(this, CurrentViewState, true);
Run Code Online (Sandbox Code Playgroud)

在我的XAML中有一个简单的GRID(在页面层次结构的深处)

            <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>
Run Code Online (Sandbox Code Playgroud)

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

VisualStateManager.GoToState(this, CurrentViewState, true);
Run Code Online (Sandbox Code Playgroud)

这是".但我不知道应该是什么,将其设置为网格或不允许其中一个矩形.

        IList<VisualStateGroup> visualStateGroups = VisualStateManager.GetVisualStateGroups(this);
        int count= visualStateGroups.Count;      
Run Code Online (Sandbox Code Playgroud)

伯爵是0.

SPQ*_*QR3 9

我发现:VisualStateManager必须是Page的直接子节点的直接子节点.

<Page>
    <Grid>
        <VisualStateManager...>
        </VisualStateManager...>

        <!-- deep in the hierarchy somewhere -->
                     <Grid>
                          <Rectangle/>
                          <Rectangle/>
                          <Rectangle/>
                     </Grid>
    </Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)

我尝试将它添加为Page的直接子项,但是没有用.我根本不了解这背后的逻辑.