Skip to content

Commit

Permalink
Add ToggleType and related properties to MenuItem (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Jul 31, 2024
1 parent bb21b83 commit cb74cca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ module WindowMenuDemo =
MenuItem.create [
MenuItem.header "Light"
MenuItem.onClick (fun _ -> "#e74c3c" |> SetColor |> dispatch)
MenuItem.toggleType MenuItemToggleType.Radio
]
MenuItem.create [
MenuItem.header "Dark"
MenuItem.onClick (fun _ -> "#c0392b" |> SetColor |> dispatch)
MenuItem.toggleType MenuItemToggleType.Radio
]
]
]
Expand Down
11 changes: 10 additions & 1 deletion src/Avalonia.FuncUI/DSL/MenuItem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ module MenuItem =
AttrBuilder<'t>.CreateSubscription<RoutedEventArgs>(MenuItem.PointerExitedItemEvent, func, ?subPatchOptions = subPatchOptions)

static member onSubMenuOpened<'t when 't :> MenuItem>(func: RoutedEventArgs -> unit, ?subPatchOptions) =
AttrBuilder<'t>.CreateSubscription<RoutedEventArgs>(MenuItem.SubmenuOpenedEvent, func, ?subPatchOptions = subPatchOptions)
AttrBuilder<'t>.CreateSubscription<RoutedEventArgs>(MenuItem.SubmenuOpenedEvent, func, ?subPatchOptions = subPatchOptions)

static member toggleType<'t when 't :> MenuItem>(toggleType: MenuItemToggleType) : IAttr<'t> =
AttrBuilder<'t>.CreateProperty<MenuItemToggleType>(MenuItem.ToggleTypeProperty, toggleType, ValueNone)

static member isChecked<'t when 't :> MenuItem>(isChecked: bool) : IAttr<'t> =
AttrBuilder<'t>.CreateProperty<bool>(MenuItem.IsCheckedProperty, isChecked, ValueNone)

static member groupName<'t when 't :> MenuItem>(groupName: string) : IAttr<'t> =
AttrBuilder<'t>.CreateProperty<string>(MenuItem.GroupNameProperty, groupName, ValueNone)

0 comments on commit cb74cca

Please sign in to comment.