All my binding code is in code-behind. I am using:
this.cboPB.ItemsSource = MyClass.Instance.MyDictionary();
this.cboPB.DisplayMemberPath = "Value";
this.cboPB.SelectedItem = "Key"; // THIS IS NOT AVAILABLE - HOW DO IDO THIS?
The dictionary referenced above is defined as type MyDictionary<int, string>();
Please help. Thanks.
Hello Jay and thank you for posting!
XamComboEditor expects an object of the source type for the SelectedItem. In this case, as you are using a dictionary, an element from the dictionary could be set like this: cboPB.SelectedItem = dict.ElementAt(1);
I have attached a sample project regarding the same. Please let me know if you need additional assistance.
Got it - thanks.
Thank you for your feedback Jay. This could help to other community members as well.
Actually, let's say the user selects a value in the combo-box, and click a button on the form, how do I get the selected key/value?
myValue = this.cbo.Value; // this does not work as Value is an element of the Dictionary.
In your example, if the user selects "three", how do I get: myValue = 3 // this would be in the code behind a button on the form.
Thanks.
Hello Jay,
The SelectedItem of the combo editor could be accessed using the SelecteItem property. The following code snippet shows how to get Key and Value of the returned KeyValuePair :
var myValue = ((KeyValuePair<int, string>)cboPB.SelectedItem).Value;
var myKey = ((KeyValuePair<int, string>)cboPB.SelectedItem).Key;
Hi Jay,
I am just checking if my last reply was helpful for you.
If you require any further assistance, please do not hesitate to ask.