1
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 5 years have passed since last update.

WPF sliderで小数点以下無効にして、整数のみ入力可とする方法

Last updated at Posted at 2020-04-17

WPF sliderで小数点以下無効にして、整数のみ入力可とする方法

Sliderのプロパティで以下の設定をする。

IsSnapToTickEnabled="True" TickFrequency="1"

解決した課題:

最初、Sliderと対応するTextBoxの表示書式を

{Binding Value, ElementName=sliderLeft1, StringFormat={}{0:0}}

等として、小数点以下を表示しないようにしていたが、

これだと、小数点以下が四捨五入されて表示されていて、

例えば、「2.8 → 3」になってるケースがあり、

設定値取得側でも小数点以下の扱いについて四捨五入か切り捨てか、など意識しなくてはならなくなり そこが煩雑になってしまっていた。

上記の設定により、小数点以下は必ず0になるので、切り捨てか四捨五入かの意識をする必要はなくなった。

確認環境:

  • WPF
  • .NET Core 3.1 (SDK ver.3.1.201)
  • Visual Studio Community 2019 ver.16.5.4

自ブログURL

1
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
1
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?