Getting value of "System.Windows.Controls.TextBlock" when binding to Silverlight ComboBox

Posted by sipwiz on Stack Overflow See other posts from Stack Overflow or by sipwiz
Published on 2011-03-15T12:47:53Z Indexed on 2011/03/16 8:10 UTC
Read the original article Hit count: 240

I'm attempting to use a Silverlight ComboBox with a static list of elements in a very simple binding scenario. The problem is the selected item is not returning me the Text of the TextBlock within the ComboBox and is instead returning "System.Windows.Controls.TextBlock".

My XAML is:

<ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
    <TextBlock FontSize="11" Text="Afghanistan" />
    <TextBlock FontSize="11" Text="Albania" />
    <TextBlock FontSize="11" Text="Algeria" /> 
</ComboBox>

In my C# file I'm binding to the ComboBox using:

Customer customer = new Customer() { Country = "Albania" };
DataContext = customer;

The binding does not result in Albania as the selected country and updating the ComboBox choice results in the Country being set to "System.Windows.Controls.TextBlock". I've tried fiddling around with DisplayMemberPath and SelectedValuePath but haven't found the answer. I suspect it's something really simple I'm missing.

© Stack Overflow or respective owner

Related posts about databinding

Related posts about silverlight-4.0