Skip to content

What's the way to find the Window that references UserControl? #15765

Closed Answered by thevortexcloud
IronEaterBeast asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the TopLevel APIs.

https://docs.avaloniaui.net/docs/concepts/toplevel

EG

var window = TopLevel.GetTopLevel(this) as Window;

Windows themselves inherit from TopLevel

public class WindowBase : TopLevel

But you should probably still check if the top level is actually a window as there are a few things that implement it which you may run into depending on how your app runs. That said I have never seen it return anything but a Window when running a desktop app. Not sure what it returns on non desktop apps.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@IronEaterBeast
Comment options

@workgroupengineering
Comment options

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