编写 UWP 程序时常常需要使用特定 Windows 版本的 API,例如项目运行所需的最低 Windows 版本设置为 1709 (Build 16299),但在代码中使用了1809 (Build 17763) 以上才支持的API。如果在 XAML 代码中使用,我们需要使用条件 XAML。例如:
<Page
x:Class="ConditionalTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock contract5Present:Text="Hello, Conditional XAML"/>
</Grid>
</Page>
该样例来自微软 Docs。其中IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)
验证了UniversalApiContract=5
的可用性,该版本指向Windows 秋季创意者更新(Version 1709, Build 16299)。通过使用条件XAML,1703 及以下版本的 Windows 将无法显示该文本块。
Windows通过查看 Windows SDK 安装目录 %PROGRAMFILES(X86)%\Windows Kits\10\Platforms\UAP\[具体SDK版本]
下 PreviousPlatforms.xml
文件,可查看所有 Windows 发行版的 UniversalApiContract
版本号。现整理如下:
Windows 版本 | Build | UniversalApiContract 版本 |
---|---|---|
Windows 10 (1507) | 10240 | 1 |
Windows 10 November Update (1511) | 10586 | 2 |
Windows 10 Anniversary Update (1607) | 14393 | 3 |
Windows 10 Creators Update (1703) | 15063 | 4 |
Windows 10 Fall Creators Update (1709) | 16299 | 5 |
Windows 10, version 1803 | 17134 | 6 |
Windows 10, version 1809 | 17763 | 7 |
Windows 10, version 1903 | 18362 | 8 |
Windows 10, version 2004 | 19041 | 10 |
Windows 10, version 2006 | 19645 | 11 |
Windows 10, version 2104 | 20348 | 12 |
Windows 11 (21H2) | 22000 | 13 |
不知出于什么原因,未找到 UniversalApiContract
版本9对应的 Windows 版本,估计为20H1的某次预览版更新。
转载请注明来源。
文章地址 https://blog.csdn.net/brandonw3612/article/details/119704720