对于wpf组合框中的太长的文本 [英] for too long texts in wpf combobox
本文介绍了对于wpf组合框中的太长的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个组合框显示各种长度的文本。对于不长的文本,没有问题,但是文本长于组合框的宽度
我想剪切文本并添加..以正确显示它们。底线是我不想改变组合框的宽度。
I have a combobox that shows texts for various lenghts. For texts that are not long there is not a problem but for the texts longer than the width of combobox I would like to cut the texts and add .. for to show them properly. The bottom line is that I don't want to change the width of the combobox. Could you please provide help ?
提前感谢
推荐答案
为 ComboBox
定制 ItemTemplate
,它使用 TextBlock
将 TextTrimming
属性设置为 CharacterEllipsis
。
Use a custom ItemTemplate
for your ComboBox
, which makes use of a TextBlock
with the TextTrimming
property set to CharacterEllipsis
.
示例:
<ComboBox ItemsSource="..." SelectedValuePath="...">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding ...}"
TextTrimming="CharacterEllipsis" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
这篇关于对于wpf组合框中的太长的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文