15,894,405 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Use my saved
content filters
ellipsis in combo box contentpresenter
Ask a Question
All
Questions
All
Unanswered
FAQ
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
Quote Selected Text
B
I
U
S
small
BIG
code
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
var
<
>
&
link
[^]
encode
untab
case
indent
outdent
OK
Paste as
Strip HTML
Encode HTML
Paste as-is
Code block
Quoted Text
Best guess
To display as
The content must be between 30 and 50000 characters.
Treat my content as plain text, not as HTML
Preview
0
…
Existing Members
Sign in to your account
...or Join us
Download, Vote, Comment, Publish.
Your Email
Password
Forgot your password?
Your Email
This email is in use. Do you need your
password
?
Optional Password
I have read and agree to the
Terms of Service
and
Privacy Policy
Please subscribe me to the CodeProject newsletters
Cancel
Submit your solution
When answering a question please:
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
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.
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