WPF 滑块的行为类似于组合框

发布于 2025-01-04 14:27:56 字数 425 浏览 4 评论 0原文

我需要一个控件,用户只能选择一个选项。组合框很好,单选按钮也可以,但出于某种目的,我想到了另一个疯狂但有趣的解决方案。

窗口上应该有一个滑块控件以及该滑动控件的三个可能位置。我知道通过设置滑块的 MinimumMaximum 加上 TickFrequencyIsSnapToTickEnabled 属性可以轻松实现这一点。

现在,有没有办法在滑块的左/右边缘和中心添加标签,显示滑块内的用户选项?或者是否有必要在下面放置标签/文本块?

最后,尽管最重要的是,如何将整数滑块位置与字符串选项相关联?我考虑过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2025-01-11 14:27:56

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文