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属性得到我们期望的结果,具体的逻辑也很简单,希望本篇能提供给需要的朋友小小的帮助.      

  • 相关阅读:
    MVC基础
    JQuery基本知识、选择器、事件、DOM操作、动画
    LinQ各种方式查询、组合查询、IQueryable集合类型
    LinQ 创建连接、简单增删改查
    webform-AJAX
    JavaScricp(总回顾)
    响应式布局(收藏)
    webform:分页组合查询
    webform:图片水印、验证码制作
    【转】开发人员一定要加入收藏夹的网站
  • 原文地址:https://www.cnblogs.com/626498301/p/2381593.html
Copyright © 2011-2022 走看看