Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf debug error output System.WIndows.Data Error 25

I have a custom styled Combobox which works fine. It is placed inside a usercontrol and bound to a data structure. I use DisplayMemberPath to show only one element in the Combobox TextBox. The ComboBox Style is taken from MSDN and used many times. So it's not displayed here.

<UserControl x:Class="wpf.projext1.MyComboBox"
         x:Name="MyControl"
         ...
    <ComboBox Style="{StaticResource ComboBoxStyle}"
                  Text="{Binding ElementName=MyControl, Path=Text}"
                  IsEditable="True"
                  IsTextSearchEnabled="False"
                  StaysOpenOnEdit="True"
                  ItemsSource="{Binding ElementName=MyControl, Path=MyItemsSource}"
                  DisplayMemberPath="Name"
    </ComboBox

I get the following annoying error message populating the output window:

System.Windows.Data Error: 25 : Both 'ContentTemplate' and 'ContentTemplateSelector' are set;  'ContentTemplateSelector' will be ignored. ComboBoxItem:'ComboBoxItem' (Name='')

if i leave out the

DisplayMemberPath="Name"

... no debug output about error 25 is shown. But I definitely need DiplayMemberPath="Name"! Do You have an idea to fix this ?

like image 548
deafjeff Avatar asked Mar 27 '13 08:03

deafjeff


2 Answers

You can´t set both DisplayMemberPath and ItemTemplate at the same time.

DisplayMemberPath is used to tell the ItemsControl which property to display when showing your objects. It makes no sense to set this field if you're already passing a custom ItemTemplate, since you can choose how to show the object within that ItemTemplate.

Since the default Combobox style from MSDN also sets an ItemTemplate, this is likely the cause of the error.

like image 89
Blachshma Avatar answered Sep 23 '22 11:09

Blachshma


resolved: use the TextSearch attached property, no matter if TextSearch is enabled!

TextSearch.TextPath="Name"
like image 45
deafjeff Avatar answered Sep 26 '22 11:09

deafjeff