c# - WPF Ribbon Contextual Tab Visibility binding -


i finding surprisingly hard find examples of binding visibility of ribboncontextualtabgroup. have property in code-behind should decide when display ribbon tab, i've tried far has no effect. code-behind essentially:

public partial class mainwindow : ribbonwindow {     public string port { get; set; } } 

a summary of wpf code below. i'm looking solution binds visibility property whether or not mainwindow.port null.

<ribbon:ribbonwindow     ...     xmlns:src="clr-namespace:magexplorer" />      ...      <ribbon:ribbontab x:name="comtab"                        header="com"                       contextualtabgroupheader="communications">     ...     </ribbon:ribbontab>      <ribbon:ribbon.contextualtabgroups>         <ribbon:ribboncontextualtabgroup header="communications"                                          visibility="<what goes here?>" />     </ribbon:ribbon.contextualtabgroups> 

you can create converter isnotnulltovisibilityconverter

with convert method this:

public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         if (value string)         {             if (!string.isnullorempty((string)value))                 return visibility.visible;         }         else if (value != null)         {             return visibility.visible;         }          return visibility.collapsed;     } 

and put in xaml

<window.resources>     <isnotnulltovisibilityconverter x:key="isnotnulltovisibilityconverter" /> </window.resources> ... visibility="{binding path=port, converter={staticresource isnotnulltovisibilityconverter}}"  

in code behind:

public static readonly dependencyproperty portproperty =         dependencyproperty.register         ("port", typeof(string), typeof(nameofyourclass),         new propertymetadata(string.empty));  public string port     {         { return (string)getvalue(portproperty); }         set { setvalue(portproperty, value); }     } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -