Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900