【发布时间】:2023-03-24 06:47:01
【问题描述】:
我正在尝试使用以下代码在 UWP 平台上获取当前的 UI-AccentColor:
var uiSettings = new UISettings();
var accentColor = uiSettings.GetColorValue(UIColorType.Accent);
此代码适用于 v10586 和 v14939,但不适用于 v10240,但以下异常:
Unable to cast object of
type 'Windows.UI.ViewManagement.UISettings' to
type 'Windows.UI.ViewManagement.IUISettings3'.
问题:为什么此代码不适用于 v10240,尽管该方法已在使用的 ApiContract [Assembly Windows.Foundation.UniversalApiContract, Version=1.0.0.0] 中定义,而且所有 AccentColor-EnumValues 都是也在 ApiContract v1 中定义?尽管文档没有提示此类异常,但避免此类错误的最佳做法是什么?
文档指定了 v10240 的使用方法的可用性:UISettings::GetColorValue 和使用的枚举:UIColorType
我已经找到 StackOverflow Get Variations of Accent color in UWP 但这并不能解决我的问题。
【问题讨论】: