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 ?
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.
resolved: use the TextSearch attached property, no matter if TextSearch is enabled!
TextSearch.TextPath="Name"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With