简体   繁体   English

如何在UWP上适当地调整应用大小以使其可见范围? (VisibleBoundsMode似乎不起作用)

[英]How to properly resize app to visible bounds on UWP? (VisibleBoundsMode doesn't seem to work)

I have two UWP apps and after testing them out with Continuum I noticed the app bar of the OS (the bar with the Start button) at the bottom of the screen (it can be at each of the 4 edges of the screen, of course) was covering part of my app. 我有两个UWP应用程序,并用Continuum对它们进行了测试后,我注意到操作系统的应用程序栏(带有“开始”按钮的栏)位于屏幕底部(当然可以位于屏幕4个边缘的每个位置) )覆盖了我的应用程序的一部分。

Now, I'm already using ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible) before calling Window.Current.Activate() , but that doesn't seem to solve the issue. 现在,在调用Window.Current.Activate()之前,我已经在使用ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible) Window.Current.Activate() ,但这似乎无法解决问题。

1) Why is it that setting the DesiredBoundsMode property doesn't seem to work here? 1)为什么设置DesiredBoundsMode属性在这里似乎不起作用? Shouldn't that automatically resize the window content to the visible bounds (ie. excluding system overlays like the navigation bar or the app bar)? 那不应该自动将窗口内容的大小调整到可见范围(即排除导航栏或应用栏之类的系统覆盖图)吗?


The workaround I'm using for now on Windows 10 Mobile devices is to subscribe to the VisibleBoundsChanged event and then manually adjust the margins of my Window.Current.Content item to make sure it doesn't show anything behind covered areas of the screen. 我现在在Windows 10移动设备上使用的解决方法是订阅VisibleBoundsChanged事件,然后手动调整Window.Current.Content项的边距,以确保其在屏幕覆盖区域后不显示任何内容。

Basically, I use the Window.Current.Bounds property and the ApplicationView.VisibleBounds property to calculate the occluded areas on the different edges of the app window, and increase the margins from there. 基本上,我使用Window.Current.Bounds属性和ApplicationView.VisibleBounds属性来计算应用程序窗口不同边缘上的遮挡区域,并从那里增加边距。

2) Is there a proper/better way to do this? 2)是否有适当/更好的方法来做到这一点? I mean, I'm quite sure there's another method that should be used to avoid this issue (considering there are tons of different situations like Continuum, navigation bar etc... that I don't think are supposed to be manually handled one by one). 我的意思是,我很确定应该使用另一种方法来避免这个问题(考虑到有很多不同的情况,例如Continuum,导航栏等...我认为不应手动处理)一)。

Thank you for your help! 谢谢您的帮助!

Use the subscription to the event VisibleBoundsChanged. 使用事件VisibleBoundsChanged的订阅。 This is the best solution that I found. 这是我发现的最佳解决方案。

        var curr = ApplicationView.GetForCurrentView();
        if (curr.IsFullScreenMode == true)
        {
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
            curr.FullScreenSystemOverlayMode = FullScreenSystemOverlayMode.Minimal;
        }
        else
        {
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
            curr.FullScreenSystemOverlayMode = FullScreenSystemOverlayMode.Standard;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM