[UWP]支持两个版本的UWP

编程入门 行业动态 更新时间:2024-10-22 14:38:46
本文介绍了[UWP]支持两个版本的UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

xmlns:Windows10version1809 =" schemas.microsoft/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)"

xmlns:Windows10version1809="schemas.microsoft/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"

使用< NavigationView Windows10version1809:PaneDisplayMode =" Top" .... />

using <NavigationView Windows10version1809:PaneDisplayMode="Top" .... />

导致应用程序在Windows 1803上崩溃

causes app to crash on windows 1803

我希望能够在1809上方导航到1803左上方

I want to be able to have the navigation on the top on 1809 and to the left on 1803

目标窗口:1809

目标最小值:1803

target min : 1803

推荐答案

这是预期的行为。如文档所述,PaneDisplayMode是1809版的新版本。请参阅:https://docs.microsoft/en-us/windows/uwp/design/controls-and-patterns/navigationview#display-modes

This is expected behavior. As documented, PaneDisplayMode is new for version 1809. See: docs.microsoft/en-us/windows/uwp/design/controls-and-patterns/navigationview#display-modes PaneDisplayMode属性需要Windows 10,版本1809( SDK 17763 )或更高版本,或 Windows UI库。 The PaneDisplayMode property requires Windows 10, version 1809 (SDK 17763) or later, or the Windows UI Library.

这为您提供了两类解决方案:

This gives you two categories of solutions:

如果您的用户界面需要设置PaneDisplayMode,那么:

If setting PaneDisplayMode is needed for your UI then:

  • 使用Windows UI库中的Microsoft.UI.Xaml.NavigationPane控件而不是内置的Windows.UI.Xaml.NavigationPane控件

这将为您提供版本之间的一致用户界面。

This will give you a consistent UI between versions.

如果您的用户界面设置PaneDisplayMode不是必需的,或者您希望使用不同的用户界面每个版本然后(代码片段近似):

If setting PaneDisplayMode isn't essential for your UI or if you'd prefer to have different UI for each version then (code snippets approximate):

  • 根本不设置
  • 使用 条件Xaml 仅在定义了UniversalApiContract 7时设置它:
  • Don't set it at all
  • Use Conditional Xaml to set it only if UniversalApiContract 7 is defined:
<Page x:Class="ConditionalTest.MainPage" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:contract7Present="schemas.microsoft/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)"> <NavigationView contract7Present:DisplayMode="Top" /> </Page>

  • 使用 版本自适应代码,用于检查PaneDisplayMode是否存在并从代码中调用它后面
    • Use Version adaptive code to check if PaneDisplayMode exists and call it from code behind
    • if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneDisplayMode") { myNavigationView.PaneDisplayMode = NavigationViewPaneDisplayMode.Top; }

      - Rob

更多推荐

[UWP]支持两个版本的UWP

本文发布于:2023-11-15 19:15:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1597219.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   版本   UWP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!