Windows10 特定版本的目标代码,例如 Build 10586
Target code for a specific version of Windows 10, like Build 10586
如您所知,ElementCompositionPreview.GetElementVisual 可在 Windows 10 Build 10586 上访问,我想要一个可以同时针对 Build 10586 和 Build 10240 的应用程序。
有谁知道当应用程序在 Build 10586 上 运行 时如何使用 Compositor 和 ElementCompositionPreview.GetElementVisual 以及在 Build 10240 上 运行 时如何使用其他东西。
像这样:
#if WINDOWS_UWP Build 10586
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(myElement);
#endif
#if WINDOWS_UWP Build 10240
//other code
#endif
有什么想法吗?
我认为您可以使用 System.Reflection 从您的应用程序中获取 OS 版本,例如:
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
}
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
对于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.
请使用Windows.Foundation.Metadata.ApiInformationAPI动态检测特征:
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
}
}
这里有一篇介绍这个的好文章API:Dynamically detecting features with API contracts (10 by 10)
如您所知,ElementCompositionPreview.GetElementVisual 可在 Windows 10 Build 10586 上访问,我想要一个可以同时针对 Build 10586 和 Build 10240 的应用程序。
有谁知道当应用程序在 Build 10586 上 运行 时如何使用 Compositor 和 ElementCompositionPreview.GetElementVisual 以及在 Build 10240 上 运行 时如何使用其他东西。
像这样:
#if WINDOWS_UWP Build 10586
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(myElement);
#endif
#if WINDOWS_UWP Build 10240
//other code
#endif
有什么想法吗?
我认为您可以使用 System.Reflection 从您的应用程序中获取 OS 版本,例如:
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
}
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
对于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.
请使用Windows.Foundation.Metadata.ApiInformationAPI动态检测特征:
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
}
}
这里有一篇介绍这个的好文章API:Dynamically detecting features with API contracts (10 by 10)