WPF button with drop down list and arrow

前端 未结 4 1924
生来不讨喜
生来不讨喜 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:29

    The solution is to make use a menu item and decorate it.

    XAML Code:

    
        
            
        
        
            
                
                
            
        
        
            
                
                
                
            
        
    
    

    C# Code: When the menu is pressed the context menu is opened.

    private void AddPresetButton_Click(object sender, RoutedEventArgs e)
    {
        var addButton = sender as FrameworkElement;
        if (addButton != null)
        {
            addButton.ContextMenu.IsOpen = true;
        }
    }
    

提交回复
热议问题