简体   繁体   English

如何自定义WPF扩展工具包RangeSlider上的工具提示?

[英]How do I customise the tooltip on the thumbs of the WPF extended-toolkit RangeSlider?

The RangeSlider widget in the WPF extended-toolkit RangeSlider uses doubles for the values of each of the two thumbs on the slider. WPF扩展工具包RangeSlider中的RangeSlider小部件使用双精度值作为滑块上两个拇指中每个拇指的值。

I am using the slider to specify a lower DateTime and an upper DateTime. 我正在使用滑块指定较低的DateTime和较高的DateTime。 To do this I have to bind to a property which represents the DateTime as doubles (essentialy DateTime.Ticks cast to double). 为此,我必须绑定到将DateTime表示为double的属性(本质上是DateTime.Ticks转换为double)。

When hovering over the thumbs of the RangeSlider, the tooltip shown is the double value, but I want to instead show a human-readable date. 将鼠标悬停在RangeSlider的拇指上时,显示的工具提示是double值,但我想显示一个人类可读的日期。 I can do the conversion easily enough, but: 我可以轻松完成转换,但是:

How do I get the RangeSlider to show custom text in the thumb tooltips? 如何使RangeSlider在拇指工具提示中显示自定义文本?

A less appealing (but sufficient) alternative is to simply disable the thumb tooltips entirely. 一种不太吸引人(但足够)的替代方法是完全禁用拇指工具提示。 A solution for this alternative is also proving elusive. 这种替代方案也难以捉摸。

For what it's worth, I've tried inspecting the code for RangeSlider.cs using JetBrains decompiler, but it hasn't yielded any promising leads to my untrained eye. 对于它的价值,我尝试使用JetBrains反编译器检查RangeSlider.cs的代码,但并没有产生任何有希望的线索给我未经训练的眼睛。

The ToolTip you see is from the AutoToolTip of the Slider used in the RangeSlider's template. 您看到的工具提示来自RangeSlider模板中使用的Slider的AutoToolTip。

Slider exposes AutoToolTipPlacement and AutoToolTipPrecision, but it does not expose a property to change the text displayed in the ToolTip. Slider公开AutoToolTipPlacement和AutoToolTipPrecision,但不公开更改工具提示中显示的文本的属性。

However, I found an article that demonstrates a workaround that could allow you to achieve what you are looking for: 但是,我发现有一篇文章演示了一种变通方法,该变通方法可以让您实现所需的结果:

https://joshsmithonwpf.wordpress.com/2007/09/14/modifying-the-auto-tooltip-of-a-slider/ https://joshsmithonwpf.wordpress.com/2007/09/14/modifying-the-auto-tooltip-of-a-slider/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM