This project is read-only.
5
Vote

DisplayMemberPath doesn't work for ComboBox (BureauBlue)

description

This code fails for the BureauBlue theme (and possibly other themes):
<ComboBox ItemSource="{Binding Plans}" DisplayMemberPath="Name" />
 
Instead of displaying the value of the Name property of the Plan class, it just displays MyProject.Plan for every item (basically, the default for plan.ToString()).
 
One valid workaround is to define a custom DataTemplate for the ComboBox.

comments

hom_rcp wrote Mar 7, 2010 at 11:11 AM

I have some problem, Is there a solution ?

danthman wrote Mar 8, 2010 at 7:15 PM

I did something like this:
                    <ComboBox Grid.Column="2" Width="100" ItemsSource="{Binding Plans}" SelectedIndex="0">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

wrote Mar 26, 2010 at 1:44 AM

Sincorde wrote Feb 20, 2011 at 6:29 PM

I got solved changing the template of ComboboxItem, removing the setting of Content and ContentTemplate properties of ContentPresenter.

seevali wrote Nov 23, 2011 at 3:38 AM

Hay..

The "<TextBlock Text="{Binding Name}" />" doesn't show anything without ComboBox's DisplayMemberPath.
But with DisplayMemberPath it shows correctly. But gives an error message "Cannot set both DisplayMemberPath and ItemTemplate".

What's now?

wrote Feb 9, 2012 at 10:20 AM

wrote Feb 22, 2013 at 1:09 AM

pj0705 wrote Mar 4, 2013 at 10:13 PM

Open the Bureau Blue theme file and change the following line in the comboboxitem style
      <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>

To
        <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
That should retain the theme and also fix the issue.

Thanks !!