void rect_Tapped(object sender, TappedRoutedEventArgs e) { Grid grid = this.Orientation == Orientation.Horizontal ? this.GetTemplateChild(HoriontalTemplate) as Grid : this.GetTemplateChild(VerticalTemplate) as Grid; Point currentPoint = e.GetPosition(grid); double currentLength = this.Orientation == Orientation.Horizontal ? currentPoint.X : currentPoint.Y; if (currentLength > (totalLength - RangeTo) || FromThumbVisbilty == Visibility.Collapsed) { RangeTo = totalLength - currentLength <= toLength ? toLength : totalLength - currentLength; this.Value = this.Value = this.Maximum - Convert.ToInt32((RangeTo - toLength) / perValue) == this.FromValue ? this.FromValue + 1 : this.Maximum - Convert.ToInt32((RangeTo - toLength) / perValue); MaxValue = Value.ToString(); ShowRightPop(); } else { RangeFrom = currentLength <= fromLength ? fromLength : currentLength; this.FromValue = Convert.ToInt32((RangeFrom - fromLength) / perValue) == this.Value ? this.Value - 1 : Convert.ToInt32((RangeFrom - fromLength) / perValue); MinValue = FromValue.ToString(); ShowLeftPop(); } }
void fromThumb_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { (GetTemplateChild(popLeftHoriontal) as Grid).Visibility = Visibility.Visible; (GetTemplateChild(popLeftVertical) as Grid).Visibility = Visibility.Visible; if (this.Orientation == Orientation.Horizontal) { if (RangeFrom + (e.Position.X - FoucsPoint.X) >= thumbFrom.Width && RangeFrom + (e.Position.X - FoucsPoint.X) <= this.Width - RangeTo - thumbFrom.Width / 2) { RangeFrom = RangeFrom + (e.Position.X - FoucsPoint.X); } else if (RangeFrom + (e.Position.X - FoucsPoint.X) < thumbFrom.Width) { RangeFrom = fromLength; } else if (RangeFrom + (e.Position.X - FoucsPoint.X) > this.Width - RangeTo - thumbFrom.Width / 2) { RangeFrom = this.Width - RangeTo - thumbFrom.Width / 2; } } else { if (RangeFrom + (e.Position.Y - FoucsPoint.Y) >= thumbFrom.Height && RangeFrom + (e.Position.Y - FoucsPoint.Y) <= this.Height - RangeTo - thumbFrom.Height / 2) { RangeFrom = RangeFrom + (e.Position.Y - FoucsPoint.Y); } else if (RangeFrom + (e.Position.Y - FoucsPoint.Y) < thumbFrom.Height) { RangeFrom = fromLength; } else if (RangeFrom + (e.Position.Y - FoucsPoint.Y) > this.Height - RangeTo - thumbFrom.Height / 2) { RangeFrom = this.Height - RangeTo - thumbFrom.Height / 2; } } this.FromValue = Convert.ToInt32((RangeFrom - fromLength) / perValue) + this.Minimum == this.Value ? this.Value - 1 : Convert.ToInt32((RangeFrom - fromLength) / perValue) + this.Minimum; MinValue = FromValue.ToString(); }
void InitRangeSlider() { try { (this.GetTemplateChild(HoriontalTemplate) as Grid).Visibility = this.Orientation == Orientation.Vertical ? Visibility.Collapsed : Visibility.Visible; (this.GetTemplateChild(VerticalTemplate) as Grid).Visibility = this.Orientation == Orientation.Vertical ? Visibility.Visible : Visibility.Collapsed; thumbFrom = this.Orientation == Orientation.Vertical ? this.GetTemplateChild(thumbVerticalFrom) as Thumb : this.GetTemplateChild(thumbHoriontalFrom) as Thumb; thumbTo = this.Orientation == Orientation.Vertical ? this.GetTemplateChild(thumbVerticalTo) as Thumb : this.GetTemplateChild(thumbHoriontalTo) as Thumb; fromLength = this.Orientation == Orientation.Vertical ? this.thumbFrom.Height : this.thumbFrom.Width; toLength = this.Orientation == Orientation.Vertical ? this.thumbTo.Height : this.thumbTo.Width; totalLength = this.Orientation == Orientation.Vertical ? this.Height : this.Width; } catch { } totalValue = FromThumbVisbilty == Visibility.Visible ? totalLength - fromLength - toLength - toLength / 2 : totalLength - toLength; if ((this.Maximum - this.Minimum) >= 0) { perValue = totalValue / (this.Maximum - this.Minimum); if (FromThumbVisbilty == Visibility.Collapsed) { RangeFrom = 0; RangeTo = perValue * (this.Maximum - this.Value) + toLength; } else { RangeFrom = perValue * (FromValue - this.Minimum) + fromLength; RangeTo = perValue * (this.Maximum - Value) + toLength; } } MinValue = FromValue.ToString(); MaxValue = Value.ToString(); if (thumbFrom != null) { thumbFrom.ManipulationStarted += fromThumb_ManipulationStarted; thumbFrom.ManipulationDelta += fromThumb_ManipulationDelta; thumbFrom.PointerEntered += thumbFrom_PointerEntered; thumbFrom.ManipulationCompleted += thumbFrom_ManipulationCompleted; thumbFrom.LostFocus += thumbTo_LostFocus; thumbFrom.PointerExited += thumbTo_PointerExited; } if (thumbTo != null) { thumbTo.ManipulationStarted += thumbTo_ManipulationStarted; thumbTo.ManipulationDelta += thumbTo_ManipulationDelta; thumbTo.PointerEntered += thumbTo_PointerEntered; thumbTo.ManipulationCompleted += thumbFrom_ManipulationCompleted; thumbTo.LostFocus += thumbTo_LostFocus; thumbTo.PointerExited += thumbTo_PointerExited; } try { Grid rectLeftHoriontal = this.GetTemplateChild(gridLeftHoriontal) as Grid; Rectangle MiddleHoriontal = this.GetTemplateChild(rectMiddleHoriontal) as Rectangle; Grid rectRightHoriontal = this.GetTemplateChild(gridRightHoriontal) as Grid; Grid rectLeftVertical = this.GetTemplateChild(gridLeftVertical) as Grid; Rectangle MiddleVertical = this.GetTemplateChild(rectMiddleVertical) as Rectangle; Grid rectRightVertical = this.GetTemplateChild(gridRightVertical) as Grid; rectLeftHoriontal.Tapped += rect_Tapped; MiddleHoriontal.Tapped += rect_Tapped; rectRightHoriontal.Tapped += rect_Tapped; rectLeftVertical.Tapped += rect_Tapped; MiddleVertical.Tapped += rect_Tapped; rectRightVertical.Tapped += rect_Tapped; } catch { } }