我可以在XAML Islands的WPF中使用ContentDialog吗

问题描述

在某些情况下,我想调用Windows 10样式对话框,因为它更美观,更现代。 但是我们的项目使用WPF,因此无法直接调用ContentDialog

我不确定XAML Islands是否可以满足我的要求。

我遵循了MS的文档,在XAML中添加了WindowsXamlHost,并在ChildChanged回调中设置了Title,Content等属性,但它引发了异常:

System.ArgumentException: Value does not fall within the expected range.
   at Windows.UI.Xaml.Controls.ContentDialog.ShowAsync()
   at WpfApp1.MainWindow.WindowsXamlHost_ChildChanged(Object sender,EventArgs e)

XAML

<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.ContentDialog" ChildChanged="ChildChanged"  />

C#

        private async void ChildChanged(object sender,EventArgs e)
        {
            WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender;

            ContentDialog noWifiDialog = (ContentDialog)windowsXamlHost.Child;

            noWifiDialog.Title = "No wifi connection";
            noWifiDialog.Content = "Check your connection and try again.";
            noWifiDialog.CloseButtonText = "Ok";

            await noWifiDialog.ShowAsync();
        }

如果我遵循另一个文档:https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/windowsxamlhost 当我致电ShowAsync()

时,也会显示相同的例外情况

有人可以帮助我吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)