WPF 滑块的行为类似于组合框
我需要一个控件,用户只能选择一个选项。组合框很好,单选按钮也可以,但出于某种目的,我想到了另一个疯狂但有趣的解决方案。
窗口上应该有一个滑块控件以及该滑动控件的三个可能位置。我知道通过设置滑块的 Minimum
和 Maximum
加上 TickFrequency
和 IsSnapToTickEnabled
属性可以轻松实现这一点。
现在,有没有办法在滑块的左/右边缘和中心添加标签,显示滑块内的用户选项?或者是否有必要在下面放置标签/文本块?
最后,尽管最重要的是,如何将整数滑块位置与字符串选项相关联?我考虑过 switch,但这是 wpf - 有“更多 wpf”解决方案,不是吗?
只需将滑块的骑手拖动到其位置,然后将 set 类字符串属性绑定到适当的值即可。
I need a control where user can pick only one option. Combobox is fine, radiobuttons are ok, but for some purpose I think about another crazy, but interesting solution.
There should be a slider control on a window and three possible positions of this sliding thing. I know this can be easily accomplished by setting slider's Minimum
and Maximum
plus TickFrequency
and IsSnapToTickEnabled
properties.
Now, is there a way how to add labels on left/right edge and center of slider showing user options within the slider? Or is it neccessary place labels/textblock below?
Last, though the most important thing is, how to associate integer slider positions with string options? I thought about switch, but this is wpf - there is "more wpf" solution, isn't it?
Just drag slider's rider to it's position and by binding set class string property to appropriate value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WPF 中的每个控件都可以完全修改其视觉效果以满足您的需求。这就是 WPF 相对于 WinForms 的优点。
您的滑块中可以有
TextBlock
吗?绝对地。随心所欲地设计风格,随心所欲。您可以通过 MSDN 杂志找到一篇很棒的文章,其中概述了自定义 WPF 控件。对于整数值,使用 IVauleConverter 将值转换为无论你喜欢什么。
Every control within WPF can have its visuals completely modified to suit your needs. This was/is the beauty of WPF over WinForms.
Can your slider have a
TextBlock
within it? Absolutely. Style as you desire and be on your way. A great article can be found via MSDN Magazine which outlines the approach to customizing WPF controls.With regard to the integer values, use an IVauleConverter to translate the values to whatever you prefer.