We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi,
I am struggling to implement a NativeMenu in a declarative Window. Any suggestions?
Update, I managed to get it working with the following:
using AvaloniaEdit.Utils; namespace App.Views; public static class MainWindow { public static Window Build(MainViewModel vm) => (Window)new Window() .Title("App") .UseLayoutRounding(true) .SetProp(NativeMenu.MenuProperty, new NativeMenu() .Items([ new NativeMenuItem() .Header("File") .Items([ new NativeMenuItem() .Header("Open") .Command(vm.OpenClustersCommand), new NativeMenuItemSeparator(), new NativeMenuItem() .Header("Close") .Command(vm.CloseCommand), ]) ) .Content( new MainView() ); } public static class WindowExtensions { public static NativeMenu Items(this NativeMenu menu, NativeMenuItemBase[] items) { menu.Items.AddRange(items); return menu; } public static NativeMenuItem Items(this NativeMenuItem menu, NativeMenuItemBase[] items) { menu.Menu ??= []; menu.Menu.Items.AddRange(items); return menu; } }
The text was updated successfully, but these errors were encountered:
I got it to work declaratively by adding this under the <Window> element:
<Window>
<NativeMenu.Menu> <NativeMenu> <NativeMenuItem Header="{Binding BackCommandCaption}" Command="{Binding NavigateBackCommand}" IsVisible="{Binding IsNavigateBackVisible}" /> <NativeMenuItem Header="{Binding AppMenuCaption}"> <NativeMenu> <NativeMenuItem Header="{Binding HomeCommandCaption}" Command="{Binding HomeCommand}" /> <NativeMenuItem Header="{Binding AddressBookCommandCaption}" Command="{Binding AddressBookCommand}" /> <NativeMenuItem Header="{Binding AccountsListCommandCaption}" Command="{Binding AccountsListCommand}" /> <NativeMenuItemSeparator /> <NativeMenuItem Header="{Binding SettingsCommandCaption}" Command="{Binding SettingsCommand}" /> <NativeMenuItem Header="{Binding BackupCommandCaption}" Command="{Binding BackupCommand}" /> <NativeMenuItemSeparator /> <NativeMenuItem Header="{Binding AboutCommandCaption}" Command="{Binding AboutCommand}" /> </NativeMenu> </NativeMenuItem> <NativeMenuItem Header="{Binding ToolsMenuCaption}"> <NativeMenu> <NativeMenuItem Header="{Binding AddressCheckCommandCaption}" Command="{Binding AddressCheckCommand}" /> </NativeMenu> </NativeMenuItem> </NativeMenu> </NativeMenu.Menu>
Sorry, something went wrong.
No branches or pull requests
Hi,
I am struggling to implement a NativeMenu in a declarative Window. Any suggestions?
Update, I managed to get it working with the following:
The text was updated successfully, but these errors were encountered: