Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have built an unpackaged app with .Net6 and WinUI3. Before launching the Main Window, i do some checks and API Requests. If one fails, i would like to communicate it to the user.

I built a method:

C#
internal static async void DisplayInfoDialog(string title, string content)
		{
			ContentDialog infoDialog = new ContentDialog()
			{
				Title = title,
				Content = @content,
				CloseButtonText = "Ok",
				XamlRoot = Window.Current.Content.XamlRoot,
			};

			await infoDialog.ShowAsync();
		}


I'm tying to use it like:

C#
DisplayInfoDialog("Fail", "It fails because");


What I have tried:

Currently i'm getting a "System.NullReferenceException: "Object reference not set to an instance of an object.""

Without XamlRoot i'm getting: "System.ArgumentException: "Value does not fall within the expected range."
Posted
Updated 6-Jun-22 0:16am
v2
Comments
Richard MacCutchan 6-Jun-22 5:40am    
I am guessing that the line that raises the error is the one referring to XamlRoot. If that is the case then you need to find out why that is not returning a valid reference.

1 solution

Hello

Put the XAMLRoot of the <grid> in the windows
With Winui3, Windows has no xamlroot
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900