[英]Target code for a specific version of Windows 10, like Build 10586
As you know ElementCompositionPreview.GetElementVisual is accessible on Windows 10 Build 10586, I would like to have one application that can target both Build 10586 and Build 10240. 如您所知,在Windows 10 Build 10586上可以访问ElementCompositionPreview.GetElementVisual,我希望有一个可以同时针对Build 10586和Build 10240的应用程序。
Does anyone have an idea of how I could use Compositor and ElementCompositionPreview.GetElementVisual when the application is running on Build 10586 and something else when it is running the build 10240. 有没有人知道如何在Build 10586上运行应用程序时使用Compositor和ElementCompositionPreview.GetElementVisual,以及运行build 10240时的其他内容。
Something like this: 像这样的东西:
#if WINDOWS_UWP Build 10586
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(myElement);
#endif
#if WINDOWS_UWP Build 10240
//other code
#endif
Any idea? 任何的想法?
As you know ElementCompositionPreview.GetElementVisual is accessible on Windows 10 Build 10586, I would like to have one application that can target both Build 10586 and Build 10240
如您所知,在Windows 10 Build 10586上可以访问ElementCompositionPreview.GetElementVisual,我希望有一个可以同时针对Build 10586和Build 10240的应用程序
For UWP app, there is only one Target version, for your requirement, we can set Target version to Build 10586 and the Min version: Build 10240 对于UWP应用程序,只有一个Target版本,根据您的要求,我们可以将Target版本设置为Build 10586和Min版本:Build 10240
Does anyone have an idea of how I could use Compositor and ElementCompositionPreview.GetElementVisual when the application is running on Build 10586 and something else when it is running the build 10240.
有没有人知道如何在Build 10586上运行应用程序时使用Compositor和ElementCompositionPreview.GetElementVisual,以及运行build 10240时的其他内容。
Please use Windows.Foundation.Metadata.ApiInformation API to dynamically detect features: 请使用Windows.Foundation.Metadata.ApiInformation API动态检测功能:
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Hosting.ElementCompositionPreview"))
{
if (Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.UI.Xaml.Hosting.ElementCompositionPreview", "GetElementVisual"))
{
_compositor = new Windows.UI.Composition.Compositor();
_root = Windows.UI.Xaml.Hosting.ElementCompositionPreview.GetElementVisual(btn1);
}
else
{
//Do other things
}
}
Here is a good article to introduce this API: Dynamically detecting features with API contracts (10 by 10) 以下是介绍此API的好文章: 使用API合同动态检测功能(10 x 10)
I think you can use System.Reflection to get the OS version from your app for example like this: 我认为您可以使用System.Reflection从您的应用程序获取操作系统版本,例如:
var analyticsInfoType = Type.GetType("Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime");
var versionInfoType = Type.GetType("Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime");
if (analyticsInfoType == null || versionInfoType == null)
{
//not on Windows 10
return;
}
var versionInfoProperty = analyticsInfoType.GetRuntimeProperty("VersionInfo");
object versionInfo = versionInfoProperty.GetValue(null);
var versionProperty = versionInfoType.GetRuntimeProperty("DeviceFamilyVersion");
object familyVersion = versionProperty.GetValue(versionInfo);
long versionBytes;
if (!long.TryParse(familyVersion.ToString(), out versionBytes))
{
//can't parse version number
return;
}
Version DeviceVersion = new Version((ushort)(versionBytes >> 48),
(ushort)(versionBytes >> 32),
(ushort)(versionBytes >> 16),
(ushort)(versionBytes));
if ((ushort)(versionBytes >> 16) == 10586)
{
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(myElement);
}
else
{
//other code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.