views:

105

answers:

1

Hi

In my project I am using a ComboBox with my custom objects like Employees and using DisplayMemberPath="Description". This all works perfectly as expected.

Because this application is targeted to be used with a touchscreen, I had to style the scrollbar and make it wider which meant that I had to create a new template for the ScrolViewer. This also turned out quite nicely.

The problem comes in when I had to create a new ControlTemplate for the ComboBox which I need so that I can add the ScrollViewerControlTemplate to the ScrollViewer of the ComboBox. I used Blend to generate the ControlTemplate for me and then Bound the ScrollViewerControlTemplate to the ScrollViewer within the ComboBox ControlTemplate.

Excelent, only problem is that the ComboBox displays the correct text within the dropdown part of the control but the ToggleButton part of the control displays the Object Type which is [NameSpace].Employee.

I tried changing the ContentPresenter but without to much success.

<ContentPresenter 
                    Content="{TemplateBinding SelectionBoxItem}" 
                    ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" 
                    ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" 
                    Margin="{TemplateBinding Padding}" 
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

Any help would be greatly appreciated.

A: 

In your ComboBox template, the content of that area should be bound to the SelectionBoxItem properties. So, if you are using a ContentPresenter to display the selection:

<ContentPresenter ContentSource="SelectionBoxItem" />

If you are using a ToggleButton's content area, you would do something like so:

<ToggleButton Content="{TemplateBinding SelectionBoxItem}"
              ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" />
Abe Heidebrecht
Hey fella, sorry I cant mark this as the answer for you as I had already changed and fixed the problem and cannot test your suggestion.
Organ Grinding Monkey