0

我正在尝试根据横向和纵向来改变我的观点。

我尝试了几个地方的代码,例如:

  1. 如何检测方向变化和改变布局?

  2. https://social.msdn.microsoft.com/Forums/en-US/a2064993-e4a9-4a58-8498-ef03ed9403f4/how-to-set-grid-row-property-in-visualstatemanager-in-windows8-app?论坛=winappswithcsharp

但这对我不起作用。不知道我做错了什么。?我正在从模拟器中对其进行测试。

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="1*" />
            <RowDefinition Height="18*" />
        </Grid.RowDefinitions>
<Grid/>
<Grid Grid.Row=1/>
<Grid Grid.Row="2">
    <Grid.RowDefinitions>
        <RowDefinition Height="4*" />
        <RowDefinition Height="14*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Row="0" x:Name="PageTotals" />

    <Grid Grid.Row="1" x:Name="PageDetails" />

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ApplicationViewStates">
            <VisualState x:Name="Filled"/>
            <VisualState x:Name="FullScreenPortrait"/>
            <VisualState x:Name="Snapped"/>
            <VisualState x:Name="FullScreenLandscape">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTotals"
                                           Storyboard.TargetProperty="(Grid.Column)">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTotals"
                                           Storyboard.TargetProperty="(Grid.RowSpan)">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageDetails"
                                           Storyboard.TargetProperty="(Grid.Column)">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageDetails"
                                           Storyboard.TargetProperty="(Grid.RowSpan)">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>
4

1 回答 1

0

的自动触发器VisualStatesLayoutAwarePage在 Windows 8 中引入的。但是在 Windows 8.1 中,Snapped屏幕的概念被删除,指导是为 320 像素(在清单中设置)或 500 像素(默认)设计您的应用程序作为最小尺寸。方向变化的自动触发器也被删除了

然而,有一些开发人员试图重现 Windows 8 的行为,例如Jeremy Likness 的这篇文章。您仍然可以在现有 8.1 API 上编写/使用与他的实现类似的代码来测试方向以及您的应用是否全屏,然后使用VisualStateManager.GoToState.

private static void SetLayout(Control control)
{
    var orientation = ApplicationView.GetForCurrentView().Orientation;
    string newMode;

    if (orientation == ApplicationViewOrientation.Landscape)
    {
        newMode = ApplicationView.GetForCurrentView().IsFullScreen ? "FullScreenLandscape" : "Filled";
    }
    else
    {
        newMode = Window.Current.Bounds.Width <= 500 ? "Snapped" : "FullScreenPortrait";
    }

    if (newMode == GetLastOrientation(control))
    {
        return;
    }

    VisualStateManager.GoToState(control, newMode, true);
    SetLastOrientation(control, newMode);
}

资料来源:杰里米的帖子

于 2015-12-18T12:02:45.970 回答