【发布时间】:2017-11-21 03:43:32
【问题描述】:
我有一个在 Windows 10 移动企业版设备上运行的基本 UAP 应用程序。但是,当我尝试打开最基本的 ContentDialogs 时,尝试设置其 CloseButtonText 时会收到 InvalidCastException
using Windows.UI.Xaml.Controls;
...
private async void DisplayNoWifiDialog()
{
ContentDialog noWifiDialog = new ContentDialog {
Title = "No wifi connection",
Content = "Check your connection and try again.",
CloseButtonText = "Ok"
};
ContentDialogResult result = await noWifiDialog.ShowAsync();
}
无法转换类型为“Windows.UI.Xaml.Controls.ContentDialog”的对象 键入“Windows.UI.Xaml.Controls.IContentDialog2”。
System.InvalidCastException:指定的强制转换无效。在 System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(对象 objSrc, IntPtr pCPCMD, IntPtr& ppTarget) 在 Windows.UI.Xaml.Controls.ContentDialog.put_CloseButtonText(字符串 值)在 MyApplication.MainPage.d__4.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.c.b__6_0(对象 州)在 System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
最低和目标 Win 10 平台分别设置为 10240 和 15063。 CloseButtonText 是在 1703 年引入的。
【问题讨论】:
-
我设置了最小和目标Win 10平台分别设置为10240和15063,没有例外。顺便说一句,我的 Windows 10 移动操作系统版本是 10.15063.297。如果您将其部署在 Windows 10 Mobile 上,您应该能够检查您手机的操作系统版本。
-
我在运行 Windows 10 Mobile Enterprise 10.0.10586.218 的设备上进行测试
-
CloseButtonText是在 Windows 10 Creators Update(引入 v10.0.15063.0)中添加的,我们无法在 Windows 10 Mobile Enterprise 10.0.10586.218 中使用它。它将抛出 InvalidCastException。 -
我在我的 Xamarin.Forms UWP 自定义渲染器中遇到了一个非常相似的问题,其中显示无法将控件(类型
TextBlock)转换为ITextBlock5。在这里发布问题:stackoverflow.com/questions/47697540/…