Function behind Button not getting executed #15618
-
I am trying to execute the function with the press of a button, and this way of executing worked for me before, the only different thing is that I am setting the data type for the button itself since the rest of the axaml relies on a different datatype. What I am expecting is a console output of "Added Path" but nothing is happening when I press the button. To clarify, all the references in terms of bindings and data type are current and link up in my IDE and don't produce any compile errors or any errors when the button is pressed and this all takes place in a window that gets created when a button is pressed. All it produces is absolutely nothing, so any help is greatly appreciated in this. :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
I highly suggest to follow the MVVM pattern and use Commands in the ViewModel. Typically you do not pass View-items to the Command, but the containing text. Sample: |
Beta Was this translation helpful? Give feedback.
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: