0

I've got a CheckComboBox bound to a list consisting of one simple index and a full description like this:

code   full_description
1      Bus
2      Car
3      Motobike

Is it possible to show just 1,2,3 for selected items and show full description when dropping down the list? I found a similar question here. But since CheckComboBox using the difference implementation, I have modified the part of class ComboBoxItemTemplateSelector as follows:

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {   
        SelectorItem selectorItem = VisualTreeHelpers.GetVisualParent<SelectorItem>(container);

        if (selectorItem != null)
        {
            return DropDownTemplate;
        }
        return SelectedTemplate;
    }

It works fine with dropdown list, but no luck with selected items. I tried to dig into the source code of CheckComboBox but got nothing. Hope someone can help me out. Thanks.

Community
  • 1
  • 1
user3496167
  • 165
  • 4
  • 11

2 Answers2

2

Did you try to just set the ContentTemplate of ItemContainerStyle?

<ComboBox.ItemContainerStyle>
    <!--Not sure what TargetType you should use-->
    <Style TargetType="ComboBoxItem">
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <!--Here goes your DropDownTemplate-->
                    <TextBlock Text="{Binding Description}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ComboBox.ItemContainerStyle>

Also, set DisplayMemberPath to your desired property.

amnezjak
  • 2,011
  • 1
  • 14
  • 18
0

1.override ToString() in your item class:

 public override string ToString()
 {
    return  full_description;
 }

2.set DisplayMemberPath to code

<CheckComboBox ItemsSource="{Binding CarList}"  
              DisplayMemberPath="code" />
Bolu
  • 8,696
  • 4
  • 38
  • 70