开发者

WPF ComboBox displaying Object Type after styling

开发者 https://www.devze.com 2022-12-24 08:00 出处:网络
In my project I am using a ComboBox with my custom objects like Employees and using DisplayMemberPath=\"Description\".

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开发者_如何学Python 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.


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}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号