In my .NET maui app I created a menu like this:
Code
But now I want to give MenuBarItems functions when clicked on. For instance, How would I close the form when a user clicks on the Exit MenuBarItem?
I tried adding Command= but that didn't seem to work. Any help is appreciated. Thanks.


Tuhin PaulRank #7 · 71.9K reputationPosted Apr 18, 2023, 10:04 PM EDT
You can handle the click event of the MenuBarItem to execute the desired function. In this case, to close the form when the Exit MenuBarItem is clicked, you can add the Clicked event handler to the MenuBarItem element and add the code to close the form in the event handler method.
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 18, 2023, 10:05 PM EDT
Sample Code:
... private void Exit_Clicked(object sender, EventArgs e) { // Close the form Application.Current.MainPage.Navigation.PopAsync(); }the Clicked event handler method is named Exit_Clicked and is called when the Exit MenuBarItem is clicked. In the method, the form is closed using the Navigation.PopAsync() method.
Bob Gatto47 reputationPosted Apr 19, 2023, 2:58 PM EDT
When I used the Clicked In the MenuBarItem it came back with a message saying:
The property 'Clicked' was not found in type 'MenuBarItem'
is ther another way?