I have a xaml file where I put the picker in and a code behind to populate it. The code used below:
Dictionary<string, int> list = new Dictionary<string, int>
{
{ "Aqua", 6},
{ "Red", 1 },
{ "Silver", 2 },
{ "Teal", 3 },
{ "White", 4 },
{ "Yellow", 55 }
};
foreach (string item in list.Keys)
{
ddlPurpose.Items.Add(item);
}
I am trying to get the value 55 when I select yellow but the only thing I get is 5. I am using this to get the selected value
var val1 = ddlPurpose.SelectedItem.ToString();
var val2 = ddlPurpose.SelectedIndex;
Is it even possible to get the key value? Have looked into the BindablePicker but that didn't seem to work at all. Any help on this is greatly appreciated.
I guess what you meant to do is:
I would recommend to get familiar with MVVM and in this specific case with Behaviors. I wrote a small example to demonstrate how it may look using MVVM: