c# - WPF selecteditem value binding -


i have combobox binded dictionary

dictionary:

public dictionary<string,datetime> timeitems { get; set; } 

<combobox grid.column="3"       horizontalcontentalignment="center"       verticalcontentalignment="center"       itemssource="{binding timeitems}"       selectedindex="0"       selecteditem="{binding selecteditem}"> 

how can bind public datetime selecteditem { get; set; } value of timeitems

you can use converter bind the value of dictionary selecteditem.

public class dictionaryvalueconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         return value;     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         return ((keyvaluepair<string, datetime>)value).value;     } } 

xaml

<combobox grid.column="3" horizontalcontentalignment="center" verticalcontentalignment="center"     itemssource="{binding timeitems}"     selecteditem="{binding selecteditem, converter={staticresource dictionaryvalueconverter}}" /> 

Comments

Popular posts from this blog

xml - Extract substrings with XSLT -

math - "ELO Rating" and how does "TSR Rating" work? -

How can do a tuple comparison in coffeescript similar to that in python? -