binding - how to bind a boolean to combobox in wpf -


well wondering how bind boolean property combobox.combobox yes/no combobox.

you use valueconverter convert boolean value combobox index , back. this:

public class booltoindexconverter : ivalueconverter     {         public object convert(object value, type targettype, object parameter, cultureinfo culture)         {             return ((bool)value == true) ? 0 : 1;            }          public object convertback(object value, type targettype, object parameter, cultureinfo culture)         {             return ((int)value == 0) ? true : false;         }     } } 

assuming yes on index 0 , no on index 1. you'd have use converter in binding selectedindex property. this, declare converter in resources section:

  <window.resources>     <local:booltoindexconverter x:key="booltoindexconverter" />   </window.resources> 

then use in binding:

<combobox selectedindex="{binding yourbooleanproperty, converter={staticresource booltoindexconverter}}"/> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -