Click here to Skip to main content
15,894,405 members

ellipsis in combo box contentpresenter

The-vister asked:

Open original thread
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
Tags: C#, WPF, Silverlight

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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