WPF - How to style the menu control to remove the left margin?

后端 未结 9 1510
余生分开走
余生分开走 2021-02-04 08:41

I have added a default menu control to my user control. I need to style the menu to remove the left margin containing the space for the icon or checkbox. How can I do this?

9条回答
  •  日久生厌
    2021-02-04 09:07

    To remove the space and never use icons you have to change the template of MenuItem.SubmenuItemTemplateKey or the template of MenuItem. If you just need to get read of the vertical line and keep using the icons space folow this answare.

    Windows with grid has my CustomContextMenu.xaml as grid resource:

    
        
            
                
            
            
                
                    
                        
                            
                                
                            
                        
                    
                    
                    
                
            
            test
        
    
    

    Here is my CustomContextMenu.xaml that has a CustomSeparatorStyle template to extend the separation line to the left margin of the context menu. And a ContextMenu template to hide the vertical line.

    
            
    
        
        
    

    The right sude menu is created with the code above. You can notice the difference in size and shadow. In order to keep the shadow of the original menu you have to exclude the Border.Effect

提交回复
热议问题