© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
16 replies
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
root/
|
| - Views/
| | - MenuBar/
| | | - FileMenu.axaml
| | - MainWindowView.axaml
In my FileMenu.axaml file I have a menu option
<MenuItem Header="_Exit" />
<MenuItem Header="_Exit" />
I know to bind it to a command I would do
<MenuItem Header="_Exit" Command="{Binding Exit}" />
<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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ make function sleep without freezing ui avalonia
C#CC# / help
2y ago
❔ Avalonia nested ItemsRepeater datatemplates
C#CC# / help
3y ago
Errors in Avalonia.UI
C#CC# / help
2y ago
Accessing nested object keys
C#CC# / help
4y ago