I’m trying to do the following.
I have a class:
public class TextField {
public string TextType { get; set; }
}
in my View I created a list:
public TextFieldEditControl()
{
InitializeComponent();
Dictionary<string, string> lst = new Dictionary<string, string>();
lst.Add("SingleLine", "Single line");
lst.Add("MultiLine", "Multi-line");
lst.Add("RichText", "Rich text");
cmbTextType.ItemsSource = lst;
}
in my XAML i have:
<ComboBox x:Name="cmbTextType" DisplayMemberPath="Value" SelectionChanged="cmbTextType_SelectionChanged"
SelectedItem="{Binding Path=TextType, Mode=TwoWay}" />
The problem is that when I check the value of the TextType property, it returns a string like that: “[SingleLine, Single line]” instead of just the Key. Where can I set it to return only the key for a Key/Value Pair?
In your title you specified Silverlight 3, which unfortunately didn’t have the SelectedValue and SelectedValuePath properties that Anthony mentions. This means that you need to do a nasty workaround to get it to work. I discuss it here in this Silverlight 2 era article of mine, in a section titled “The ComboBox Nightmare”: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-5.aspx. It was a pain in Silverlight 2, and wasn’t fixed until Silverlight 4.
Hope this helps…
Chris