如何将Slider的选择限制为SelectedRange [英] How can I restrict selection of a Slider to the SelectedRange

查看:109
本文介绍了如何将Slider的选择限制为SelectedRange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将滑块限制为选定范围。例如:



滑块最小值= 0且最大值= 10



SelectionStart = 3

SelectionEnd = 7



我想将滑块限制在3到7之间。



我希望拇指只能选择3和7以及它们之间的任何值。

拇指不能向左或向右移动。

最小值和最大值必须保持为0和10.

选中范围是动态的,例如可以改为5到10或0到6。





提前感谢。

I would like to restrict a slider to the Selected Range. Ex:

Slider with minimum=0 and maximum=10

SelectionStart=3
SelectionEnd=7

I would like to restrict the slider thumb to only between 3 and 7.

I want the thumb to only be able to select 3 and 7 and any values in between.
Thumb should not be able to move left or right of the range.
Min and Max must stay as 0 and 10.
The Selected Range is dynamic, could change to 5 to 10 or 0 to 6 for example.


thanks in advance.

推荐答案

你好,



在xaml中为ValueChanged添加一个事件处理程序:



Hello,

Add an event handler for ValueChanged in the xaml:

<slider x:name="slider" valuechanged="Slider_ValueChanged" />





检查后面代码中的滑块值:





Check the slider value in the code behind:

private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    if (e.NewValue < 3 | e.NewValue > 7)
        slider.Value = e.OldValue;
}





Valery。



Valery.


这篇关于如何将Slider的选择限制为SelectedRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆