NativeMenu
You can check the NativeMenu and NativeMenu API Avalonia docs for more information
Native menus were introduced in Avalonia in version 0.9.0, you can check the announcement to see a brief explanation on how to use them in Avalonia Applications.
Currently for Avalonia.FuncUI there is not a DSL and the NativeMenu control is in a weird spot for Avalonia.FuncUI since this control works directly on the main Application/Window object so it's tough to pull a DSL on top of that. But! thankfully you can just use plain F# for the menu as noted in this issue.
Usage
Inside your Program.fs File find the App class and be sure to set the name of your Application
type MainWindow() as this = (*... code ... *)
type App() =
inherit Application()
override this.Initialize() =
this.Styles.Load "avares://Avalonia.Themes.Default/DefaultTheme.xaml"
this.Styles.Load "avares://Avalonia.Themes.Default/Accents/BaseDark.xaml"
// 🚩name visible in native menu
this.Name <- "Counter App"
override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktopLifetime ->
desktopLifetime.MainWindow <- MainWindow()
| _ -> ()then just create a new NativeMenu
and that is enough to show your native menu. If you want to interact with the contents of your menu (the most likely scenario) you will need to add some subscriptions to hook up with your Elmish program
Last updated