user2323704
user2323704

Reputation: 943

ComboBox bind to ItemsSource object property without using the DisplayMemberPath

Probably this is a very stupid question, but I am not able to find a solution. I would like to bind the ComboBox Text property to the property of my items which are bind in ItemsSource. The problem is that I need to achieve this without the usage of DisplayMemberPath. So I am simply using the Path for Binding but this do not work:

<ComboBox IsEditable="True"
          ItemsSource="{Binding MyItemsCollection}"
          SelectedItem="{Binding MySelectedItem, Mode=TwoWay}"
          Text="{Binding Path=MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

In this case I have the .NET type name displayed instead of the value of MyProperty property.

I do not want to override the ToString in my type.

Thank you for help.

Upvotes: 1

Views: 348

Answers (1)

kmatyaszek
kmatyaszek

Reputation: 19296

You should override ToString method in the class that you binding to ComboBox.

public class YourClass
{        
    public override string ToString()
    {
        return DisplayPropName;
    }
}

Upvotes: 1

Related Questions