コード例 #1
0
        private void UpdateTickPoints()
        {
            if (_TickPoints == null)
            {
                return;
            }
            if (Ticks == null)
            {
                return;
            }

            _TickPoints.Clear();
            var TotalWidth = (PART_Ticks.ActualWidth - PART_Ticks.Margin.Right - PART_Ticks.Margin.Left);
            var ItemWidth  = TotalWidth / (Ticks.Count - 1);
            int index      = 0;

            foreach (var Value in Ticks)
            {
                var TickPoint = new TTickPoint(this, Value);
                TickPoint.Left = (int)(index * ItemWidth);
                _TickPoints.Add(TickPoint);
                index++;
            }

            if (PART_Ticks != null)
            {
                PART_Ticks.ItemsSource = _TickPoints;
            }
            SnapToNearestFromValue();
        }
コード例 #2
0
        private void SnapToNearestFromLocation()
        {
            var location = ThumbLeft;

            TTickPoint previous = null;

            foreach (var item in _TickPoints)
            {
                if (item.Previous == null)
                {
                    continue;
                }
                previous = item.Previous;

                if (location >= previous.Left && location <= item.Left)
                {
                    double LeftDelta  = location - previous.Left;
                    double RightDelta = item.Left - location;
                    if (LeftDelta < RightDelta)
                    {
                        SnapTo(previous);
                    }
                    else
                    {
                        SnapTo(item);
                    }
                    break;
                }
                else if (item.Next == null)
                {
                    SnapTo(item);
                    break;
                }
            }
        }
コード例 #3
0
 private void SnapTo(TTickPoint tick)
 {
     if (Value != tick.Value)
     {
         Value = tick.Value;
     }
     if (ThumbLeft != tick.Left)
     {
         AnimateToLocation(tick.Left);
     }
 }
コード例 #4
0
        private void SnapToNearestFromValue()
        {
            double     value    = Value;
            TTickPoint previous = null;

            if (!_TickPoints.Any())
            {
                return;
            }

            var FirstTick = _TickPoints.FirstOrDefault();
            var LastTick  = _TickPoints.LastOrDefault();

            if (value < FirstTick.Value)
            {
                SnapTo(FirstTick);

                return;
            }
            if (value > LastTick.Value)
            {
                SnapTo(LastTick);
                return;
            }
            foreach (var item in _TickPoints)
            {
                if (item.Previous == null)
                {
                    continue;
                }
                previous = item.Previous;

                if (value >= previous.Value && value <= item.Value)
                {
                    double LeftDelta  = value - previous.Value;
                    double RightDelta = item.Value - value;
                    if (LeftDelta < RightDelta)
                    {
                        SnapTo(previous);
                    }
                    else
                    {
                        SnapTo(item);
                    }
                    return;
                }
            }
        }
コード例 #5
0
        private void Part_LeftButton_Click(object sender, RoutedEventArgs e)
        {
            TTickPoint Current = _TickPoints.FirstOrDefault(t => t.Value == Value);

            if (Current == null)
            {
                return;
            }
            if (sender == Part_LeftButton && Current.Previous != null)
            {
                Value = Current.Previous.Value;
            }
            else if (sender == Part_RightButton && Current.Next != null)
            {
                Value = Current.Next.Value;
            }
        }