1

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

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

我按照MS的文档,WindowsXamlHost在XAML中添加了一个,并在回调中设置了Title,Content等属性ChildChanged,但是它抛出了一个异常:

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()

有人可以帮助我吗?

4

0 回答 0