C#C
C#2y ago
Mek

Accessing Function from Nested UI File - Avalonia

Ok so I have the following file structure for my Avalonia MVVM project

root/
|
| - Views/
| | - MenuBar/
| | | - FileMenu.axaml
| | - MainWindowView.axaml
In my FileMenu.axaml file I have a menu option
<MenuItem Header="_Exit" />
I know to bind it to a command I would do
<MenuItem Header="_Exit" Command="{Binding Exit}" />
however, the exit function is in my MainWindowViewModel. So I have two questions.

  1. Is it ok if I put the exit command in the FileMenu.axaml.cs file to exit the program?
  2. If not, do I create a ViewModel file in the same directory as the FileMenu.axaml file and then call that code behind for all of my nested menu options?
either way, if it's ok to stay in the MainWindowViewModel, then how do I properly bind to it? I remember in a Todo tutorial they did something like a this.Something.bind.x or something like that. Let me see if I can find it
Was this page helpful?