mvvm - WPF: Hiding ContextMenu when empty -


i have context menu gets menu items through databinding (i'm using mvvm pattern):

<contextmenu itemssource="{binding path=contextmenuitems}" /> 

this works fine. however, in cases when there no menu items show, don't want context menu show @ all. there way accomplish this? kind of xaml trigger maybe?

i've tried catching opened event och closing context menu when there no children. works context menu still flashes by...

maybe bind menu items collections count property , use converter set context menu's visibility.

 <contextmenu itemssource="{binding path=contextmenuitems}"               visibility="{binding path=contextmenuitems.count,converter={staticresource zerotohiddenconverter}}"> 

public  class zerotohiddenconverter:ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)      {         int count = (int) value;          if (count == 0)          {             return visibility.hidden;         }         else         {             return visibility.visible;         }     } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -