In some cases, I want to call the Windows 10 Style Dialog, because it's more beautiful and modern.
But our project is using WPF, we cannot call ContentDialog
directly.
I'm not sure if XAML Islands can meet my requirement.
I followed the document from MS, add a WindowsXamlHost
in XAML, and set Title, Content, etc. property in the ChildChanged
callback, but it throws a exception:
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();
}
And if I follow the other document: https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/windowsxamlhost
The same exception shows when I call ShowAsync()
Does anyone can help me?