0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[WPF]TextBlockで文字を省略するには

Last updated at Posted at 2020-08-06

はじめに

本記事は、開発で得た知識を備忘録として残すことを目的としています。

やりたいこと

TextBlockでTextを表示する際に、表示しきれなかった場合は語尾に「・・・」を付けて、省略されていることがわかるようにしたいです。

解決策

TextBlockにはTextTrimmingプロパティというものがあり、これを以下のように設定することで解決できました。

  • 文字単位で省略したい時は、TextTrimmingプロパティにCharacterEllipsisを設定します。
  • 単語単位で省略したい時は、TextTrimmingプロパティにWordEllipsisを設定します。

さいごに

TextBlockにはTextWrapping というテキストの折り返し方法設定できるプロパティがあるので、それに省略記号を表示するような設定があるのかと思っていました。それ専用のプロパティがあることは意外と知らない人も多いんじゃないかなと思いました。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?