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

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -