Skip to content

Running a function from the viewmodel on view load in Avalonia using the MVVM pattern #15643

Discussion options

You must be logged in to vote

If you are using ReactiveUI, there is built in functionality to trigger things when the view is activated. You just need to make your control inherit from ReactiveUserControl and make your viewmodel implement IActivatableViewModel.

https://www.reactiveui.net/docs/handbook/when-activated.html

Async can get a bit more annoying though, but there are ways to do it.

Otherwise, there is nothing in the MVVM pattern preventing your view from directly calling your view model (the view is allowed to know about the viewmodel, the viewmodel is not allowed to know about the view). It's just generally considered to be a bad idea since it can make your code less portable. But you could just have an asyn…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@matthew-west-unity
Comment options

@timunie
Comment options

Answer selected by matthew-west-unity
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