zoukankan      html  css  js  c++  java
  • Silverlight控件Slider

    Get Microsoft Silverlight

       本篇主要分享关于Slider应用上的一点问题, 相信你看完演示后,已经知道本文的意图了.

       在实际开发中,我们需要Slider根据我们设置的SmallChange进行ValueChange.SDK的Slider即使设置了SmallChange属性,

       但是在拖动Thumb时,仍会显示实际的Value.显然不能够满足我们的需求,这就需要我们手动去修改Slider.

       我相信最初使用Slider的人会和我遇到一样的问题,希望本篇的做法能提供给各位一些思路.

       我的做法重写OnValueChanged事件,直接贴出改造后的代码:

      public class RoundSlider : Slider, INotifyPropertyChanged
       {
        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }   
        public double RoundValue
        {
            get { return (SmallChange == 0 ? Value : Math.Round(Value / SmallChange) * SmallChange); }
        }
        bool _busy=false;
        double _discreteValue;
       
        protected override void OnValueChanged(double oldValue, double newValue)
        {
            if (!_busy)
            {
                _busy = true;
                if (SmallChange != 0)
                {
                    double newDiscreteValue = Math.Round(newValue / SmallChange) * SmallChange;
                    if (newDiscreteValue != _discreteValue)
                    {
                        Value = newDiscreteValue;
                        base.OnValueChanged(_discreteValue, newDiscreteValue);
                        _discreteValue = newDiscreteValue;
                    }
                }
                else
                {
                    base.OnValueChanged(oldValue, newValue);
                }
                _busy = false;
            }
            NotifyPropertyChanged("RoundValue");
        }
    }

           通过RoundValue属性得到我们期望的结果,具体的逻辑也很简单,希望本篇能提供给需要的朋友小小的帮助.      

  • 相关阅读:
    Vue.js —— 关闭eslint校验
    彻底搞懂 module.exports/exports/import/export/export default
    JS 中的原型和原型链
    TypeScript-初级-08-声明合并
    TypeScript-初级-07-泛型
    TypeScript-初级-06-类与接口
    TypeScript-初级-05-类
    TypeScript-初级-04-枚举
    TypeScript-初级-03-元组
    TypeScript-初级-02-字符串字面量类型
  • 原文地址:https://www.cnblogs.com/626498301/p/2381593.html
Copyright © 2011-2022 走看看