Application.Current.MainWindow not available in Avalonia #5779
-
Hi,
Code for my Dialog window: Xaml file for view
Code behind:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
What you can do, you can use VisualRoot property. If you are running your app from desktop environment, you can safely cast it to Window. var currentWindow = (Window)myUserControl.VisualRoot;
var advanceFilterWindow = new AdvancedFilterWindow();
advanceFilterWindow.ShowDialog(currentWindow); |
Beta Was this translation helpful? Give feedback.
Application.Current.MainWindow
is an antipattern, and is not applicable for some applications types, where "main" window is not defined.Also on some platforms there are no root windows at all: embed and mobile.
And your user control could be defined on non-"main" window.
What you can do, you can use VisualRoot property. If you are running your app from desktop environment, you can safely cast it to Window.