Skip to content

Application.Current.MainWindow not available in Avalonia #5779

Answered by maxkatz6
ShrutiJaiswal1494 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

var currentWindow = (Window)myUserControl.VisualRoot;
var advanceFilterWindow = new AdvancedFilterWindow();
advanceFilterWindow.ShowDialog(currentWindow);

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@maxkatz6
Comment options

@ShrutiJaiswal1494
Comment options

@maxkatz6
Comment options

Answer selected by maxkatz6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants