Search code examples
c#avalonia

How do I get the Window that the UserControl belongs to?


Am I trying to get the window that the usercontrol belongs to?

I am trying to open a dialog box from a custom usercontrol, the current window is needed to open it. What can I do? This is what I'm doing now, but how good is this solution?

            var window = this.GetVisualRoot();
            var result = await dialog.ShowDialog<bool>((Window)window);

Solution

  • I used this

    TopLevel.GetTopLevel(this) as Window