Desktop applications migrate to MS Store (13) - Dynamic Check Win10 API is available

Suppose we have an existing WPF program, need the support of 10 of the 1903 previous versions of Windows. At the same time in 1903 on a future release, there is an additional Ink feature.
Then we can ApiInformation.IsApiContractPresent to determine the API 1903 is available, decide whether or not to open Ink functionality to the current user method. The new student if you do not know how to use "ApiInformation.IsApiContractPresent", please refer to the "Migrating desktop applications to MS Store (4) - Desktop API program calls the Win10" .
Sample Code we were still "Migrating desktop applications to MS Store (12) - WPF using the UWP InkToolbar and InkCanvas" in WPFInkSample.git example.
First, we make sure WPFInkSample Engineering Solution can successfully compile and run.

Then create a WPF project MainUI, add a reference to the WPFInkSample. In MainWindow.xaml.cs we want to determine whether the current version of Windows 1903 or above. If it is above the 1903 edition, will start WPFInkSample.exe by Process.Start, otherwise pop MessageBox.

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
            {
                Process.Start("WPFInkSample.exe");
            }
            else
            {
                MessageBox.Show("Since version 1903, we can use UWP control in WPF project.");
            }

IsApiContractPresent first parameter is to check API name, the second parameter is the version number. From Universal device family API contracts list we can search "Windows.Foundation.UniversalApiContract", you will find the 1903 version (version 10.0.18362) in "Windows.Foundation.UniversalApiContract" The version = 8.0, while the 1809 version of the version = 7.0.

Can not find "ApiInformation.IsApiContractPresent" students remember to add in MainUI in reference to Windows.winmd is located in C: \ Program Files (x86) \ Windows Kits \ 10 \ UnionMetadata \ <sdk version> \ Facade folder.

This part describes how the WPF application dynamically determine if a Win10 API is available.
GitHub:
https://github.com/manupstairs/WPFInkSample

 

Guess you like

Origin www.cnblogs.com/manupstairs/p/11970166.html