WPF button with drop down list and arrow

前端 未结 4 1895
生来不讨喜
生来不讨喜 2021-02-18 17:08

Can someone suggest the best way to have a button with an arrow and dropdown list like in visual studio toolbar button new item. As you can find in VS the mouse hover is highlig

4条回答
  •  难免孤独
    2021-02-18 17:50

    It looks like you have three problems to solve:

    1. Styling / Layout
    2. Highlight dropdown and button OnMouseOver
    3. Change default button according to menu's last selection

    Styling / Layout

    Here are a couple of examples:

    • http://dvoituron.wordpress.com/2011/01/06/toolbar-dropdownbutton-in-wpf/
    • http://blogs.msdn.com/b/llobo/archive/2006/10/25/split-button-in-wpf.aspx

    I am sure there are many other ways (e.g. using a plain button and ComboBox styled appropriately)

    Highlighting dropdown and button OnMouseOver

    Experiment with triggers; e.g:

    • WPF Mouseover Trigger Effect for Child Controls
    • WPF - How to change children's style on mouseover of parent

    Change default button according to menu's last selection

    Try the MVVM approach: The button element will be bound to a property on your ViewModel. Each menu item will call an action (ICommand) in your ViewModel. This ViewModel will know which menu item was called, and update the button's property on the ViewModel. The button will automatically update using data binding.

提交回复
热议问题