Content Dialog - XAML Islands Winforms C#

Hemanth B 886 Reputation points
2021-11-19T06:39:48.187+00:00

Hi I am using the XAML Islands technology in Winforms .net core 3.1.
Now under a UWP Button click I am trying the following:

 ContentDialog dialog = new ContentDialog();  
            dialog.Title = "Save your work?";  
            dialog.PrimaryButtonText = "Save";  
            dialog.SecondaryButtonText = "Don't Save";  
            dialog.CloseButtonText = "Cancel";  
            dialog.DefaultButton = ContentDialogButton.Primary;  
            dialog.Content = "Somethng";  
            var result = await dialog.ShowAsync();  
  

But with this code, I am getting the following exception:

150922-image.png

What is the problem?
Does content dialog have a problem in WinForms?
Also how do I add a keyboard Accelerator to the button in Winforms c#?

Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2021-11-19T09:58:01.53+00:00

    You must set XamlRoot :

    For example, in the Button click :

     Windows.UI.Xaml.DependencyObject parent = ((Windows.UI.Xaml.FrameworkElement)sender).Parent;  
     dialog.XamlRoot = ((Windows.UI.Xaml.UIElement)parent).XamlRoot;  
    

    150849-contentdialog.jpg


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.