-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
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
Support for NativeMenu #113
Comments
Hey @JonCanning , thanks for the patience. There is currently no DSL for Native Menus. BUT, it's simple to use them with plain F#. Here is a small sample extending the CounterApp with a native menu! If you haven't done this already set the type App() =
inherit Application()
override this.Initialize() =
this.Styles.Load "resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"
this.Styles.Load "resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default"
// 🚩name visible in native menu
this.Name <- "Counter App" type MainWindow() as this =
inherit HostWindow()
do
base.Title <- "Counter Example"
base.Height <- 400.0
base.Width <- 400.0
// 🚩create menu and menu items
let incrementItem = NativeMenuItem "Increment"
let decrementItem = NativeMenuItem "Decrement"
let editCounterItem = NativeMenuItem "Edit Counter"
let editCounterMenu = NativeMenu()
editCounterItem.Menu <- editCounterMenu
editCounterMenu.Add incrementItem
editCounterMenu.Add decrementItem
let nativeMenu = NativeMenu()
nativeMenu.Add editCounterItem
// 🚩set menu
NativeMenu.SetMenu(this, nativeMenu)
// 🚩hook menu actions in Elmish
let menuSub (_state: Counter.State) =
let sub (dispatch: Counter.Msg -> unit) =
incrementItem.Clicked.Add (fun _ -> dispatch Counter.Msg.Increment)
decrementItem.Clicked.Add (fun _ -> dispatch Counter.Msg.Decrement)
()
Cmd.ofSub sub
Elmish.Program.mkSimple (fun () -> Counter.init) Counter.update Counter.view
|> Program.withHost this
// 🚩 use menu subscription
|> Program.withSubscription menuSub
|> Program.withConsoleTrace
|> Program.run hope this helps 😉 |
Hi,I aslo want to modify the menu name.but i do not know your code. could you tell me how to operate it ?? |
What exactly do you mean by menu name ? |
Ahh, I see. Thats actually in my sample: type App() =
inherit Application()
override this.Initialize() =
this.Styles.Load "resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"
this.Styles.Load "resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default"
// 🚩name visible in native menu
this.Name <- "Counter App" |
Well,thanks,but my problem are three,1st is how to modify the app menu header on osx,just like the picture you see. |
thank you ,Paste the picture for me |
I got a tip from gitter.Now,the first problem is ok, can you tell me the rest problems. |
I'd like to be able to set the NativeMenu like this:
AvaloniaUI/Avalonia#3541 (comment)
The text was updated successfully, but these errors were encountered: