辅屏视图地铁应用程序的问题

本文关键字:问题 应用程序 地铁 视图 | 更新日期: 2023-09-27 18:33:36

嘿伙计们请帮忙解决我的问题,我已经制作了一个应用程序,我必须将其上传到Windows应用商店,但问题是它不支持辅屏视图。我希望它不应该在辅屏视图中工作,当应用程序进入辅屏视图时,它只显示一条消息" 切换到全屏 "。请告诉我如何为此编写代码,以及在 XAML 或 XAML.cs 中编码的位置。提前谢谢。

辅屏视图地铁应用程序的问题

添加一个基本页面并将 XAML 替换为以下内容:

<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="App1.OopsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:common="using:App1.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid>
        <!-- Full screen content. -->
        <Grid x:Name="FullScreenGrid">
            <TextBlock>Here is your content.</TextBlock>
        </Grid>
        <!-- Snapped view content. -->
        <Grid x:Name="SnappedViewGrid" Visibility="Collapsed">
            <TextBlock>Please go back to full screen :(</TextBlock>
        </Grid>
        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait" />
                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FullScreenGrid" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SnappedViewGrid" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>

请确保将App1替换为应用命名空间,并且必须在 Common 文件夹中具有 LayoutAwarePage.cs

可能的解决方案之一

  1. 创建一个要用于贴靠的新页面
  2. 侦听用户贴靠应用时引发的事件。
  3. 导航到具有"切换到全屏"的页面
  4. 侦听用户取消捕捉时引发的事件
  5. 返回原始页面

为了实现这一目标,

在您的 App.xaml 中.cs在 OnLaunch 事件中写下这个

 Window.Current.SizeChanged += Current_SizeChanged;

现在用于事件处理程序

 void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
        ApplicationViewState viewState = ApplicationView.Value;
       if (viewState == ApplicationViewState.Snapped)
        {
            //Navigate to the new common snap page
        }          
      else{
              //Write the code to check if the previous state was snapped and then navigate back
        }
   }