Click here to Skip to main content
13,042,421 members (137,793 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi all.

I am trying to change wpf combo box style in order to add ellipsis to the combo in case of long selected item the combo show me ellipsis. so using expression bland 4 i did change the control template and i did found a content presenter in order to show the selected item. for applying ellipsis i did change the content presenter to Label and in the label template i did use texblock. but it did not work then i did bound the textblock to content presenter content.Description with is displaymemberpath of combo. the problem is i did write statically content.description maybe in other case the display member path be Name or Age or any things. do any one have an idea to meet this requiremet.this is the xaml code:
combo style:
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}">
<setter property="FocusVisualStyle" value="{StaticResource ComboBoxFocusVisual}" />
<setter property="Foreground" value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<setter property="Background" value="{StaticResource ButtonNormalBackground}" />
<setter property="BorderBrush" value="{StaticResource ButtonNormalBorder}" />
<setter property="BorderThickness" value="1" />
<setter property="ScrollViewer.HorizontalScrollBarVisibility" value="Auto" />
<setter property="ScrollViewer.VerticalScrollBarVisibility" value="Auto" />
<setter property="Padding" value="4,3" />
<setter property="ScrollViewer.CanContentScroll" value="true" />
<setter property="ScrollViewer.PanningMode" value="Both" />
<setter property="Stylus.IsFlicksEnabled" value="False" />
<setter property="Template">
<setter.value>
<controltemplate targettype="{x:Type ComboBox}">
<grid x:name="MainGrid" snapstodevicepixels="true" xmlns:x="#unknown">
<grid.columndefinitions>
<columndefinition width="*" />
<columndefinition minwidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" width="0" />

<popup x:name="PART_Popup" allowstransparency="true" grid.columnspan="2" isopen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" margin="1" popupanimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" placement="Bottom">
<microsoft_windows_themes:systemdropshadowchrome x:name="Shdw" color="Transparent" maxheight="{TemplateBinding MaxDropDownHeight}" minwidth="{Binding ActualWidth, ElementName=MainGrid}" xmlns:microsoft_windows_themes="#unknown">
<border x:name="DropDownBorder" borderbrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" borderthickness="1" removed="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<scrollviewer x:name="DropDownScrollViewer">
<grid renderoptions.cleartypehint="Enabled">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<rectangle x:name="OpaqueRect" fill="{Binding Background, ElementName=DropDownBorder}" height="{Binding ActualHeight, ElementName=DropDownBorder}" width="{Binding ActualWidth, ElementName=DropDownBorder}" />
</Canvas>
<itemspresenter x:name="ItemsPresenter" keyboardnavigation.directionalnavigation="Contained" snapstodevicepixels="{TemplateBinding SnapsToDevicePixels}" />





<togglebutton borderbrush="{TemplateBinding BorderBrush}" removed="{TemplateBinding Background}" grid.columnspan="2" ischecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" style="{StaticResource ComboBoxReadonlyToggleButton}" />

<Label ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Style="{DynamicResource LabelEllipsis}"/>

<controltemplate.triggers>
<trigger property="HasDropShadow" sourcename="PART_Popup" value="true">
<setter property="Margin" targetname="Shdw" value="0,0,5,5" />
<setter property="Color" targetname="Shdw" value="#71000000" />

<trigger property="HasItems" value="false">
<setter property="Height" targetname="DropDownBorder" value="95" />

<trigger property="IsEnabled" value="false">
<setter property="Foreground" value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
<setter property="Background" value="#FFF4F4F4" />

<trigger property="IsGrouping" value="true">
<setter property="ScrollViewer.CanContentScroll" value="false" />

<trigger property="ScrollViewer.CanContentScroll" sourcename="DropDownScrollViewer" value="false">
<setter property="Canvas.Top" targetname="OpaqueRect" value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<setter property="Canvas.Left" targetname="OpaqueRect" value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />





<Style.Triggers>
<trigger property="IsEditable" value="true">
<setter property="BorderBrush" value="{StaticResource TextBoxBorder}" />
<setter property="Background" value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<setter property="IsTabStop" value="false" />
<setter property="Padding" value="3" />
<setter property="Template" value="{StaticResource ComboBoxEditableTemplate}" />

</Style.Triggers>
</Style>

<Style x:Key="LabelEllipsis" TargetType="{x:Type Label}">
<setter property="Template">
<setter.value>
<controltemplate>

<textblock text="{Binding Content.Description,Mode=TwoWay,RelativeSource={RelativeSource AncestorType={x:Type Label},Mode=FindAncestor}}" texttrimming="CharacterEllipsis" />



</Style>

in LabelEllipsis style i did bind textbloxk text to Content.Description, Description is display member path, can any one tel me how to make it dynamic
Posted 27-Jan-13 23:25pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100