How to open a popup menu when a button is clicked?

后端 未结 4 1995
时光取名叫无心
时光取名叫无心 2020-12-30 01:14

I have a button with an Image as its content in a toolbar. I would like this button to open a menu beneath it when clicked. How?


                     


        
4条回答
  •  鱼传尺愫
    2020-12-30 02:03

    There are lots of ways to get this done and you might consider this approach...

    
        
            
                
            
            
                
                
            
        
    
    

    This wraps your button into a MenuItem that has a submenu. As shown here, the MenuItem property called IsSubMenuOpen is bound to a notifying property of type bool in your ViewModel called SomeProperty.

    You would have to have your ViewModel toggle this property depending upon what you are actually trying to do. You may want to consider making your button a toggle button so as to facilitate closing the submenu, otherwise you'll have to wire up additional behaviour in your ViewModel.

提交回复
热议问题