Skip to content

Function behind Button not getting executed #15618

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

You must be logged in to vote

A constructor will be called whenever the class is instantiated. If it's not being instantiated it wont be called. You can prove that the constructor is being called by putting a break point inside it with your IDE and seeing if it gets hit.

Avalonia generally does not try to instantiate your view models for you. You need to that yourself somehow (and in some cases explicitly set the view model as the data context for your view). The main window's view model is typically set in the App.axaml.cs file. Like this:

    public override void OnFrameworkInitializationCompleted() {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
            desktop.MainWindow = 

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@SirZeeno
Comment options

@thevortexcloud
Comment options

@SirZeeno
Comment options

@thevortexcloud
Comment options

Answer selected by SirZeeno
@SirZeeno
Comment options

@thevortexcloud
Comment options

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