Skip to content

Commit

Permalink
Merge pull request #3808 from MahApps/feature/GH-3798-RangeSlider
Browse files Browse the repository at this point in the history
Fix RangeSlider Upper/Lower value coercion and value changed events
  • Loading branch information
punker76 authored May 22, 2020
2 parents 03b5978 + 09d689a commit b2455b5
Show file tree
Hide file tree
Showing 4 changed files with 653 additions and 587 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using MahApps.Metro.Controls;
using System.Windows.Controls;

namespace MetroDemo.ExampleViews
{
Expand All @@ -14,60 +11,5 @@ public Sliders()
{
InitializeComponent();
}

private void RangeSlider_OnLowerValueChanged(object sender, RangeParameterChangedEventArgs e)
{
Trace.TraceInformation($"LowerValueChanged: {e.ParameterType}, {e.OldValue} -> {e.OldValue}");
}

private void RangeSlider_OnLowerThumbDragStarted(object sender, DragStartedEventArgs e)
{
Trace.TraceInformation("LowerThumbDragStarted");
}

private void RangeSlider_OnLowerThumbDragDelta(object sender, DragDeltaEventArgs e)
{
Trace.TraceInformation($"LowerThumbDragDelta: h={e.HorizontalChange}, v={e.VerticalChange}");
}

private void RangeSlider_OnLowerThumbDragCompleted(object sender, DragCompletedEventArgs e)
{
Trace.TraceInformation("LowerThumbDragCompleted");
}

private void RangeSlider_OnUpperValueChanged(object sender, RangeParameterChangedEventArgs e)
{
Trace.TraceInformation($"UpperValueChanged: {e.ParameterType}, {e.OldValue} -> {e.OldValue}");
}

private void RangeSlider_OnUpperThumbDragStarted(object sender, DragStartedEventArgs e)
{
Trace.TraceInformation("UpperThumbDragStarted");
}

private void RangeSlider_OnUpperThumbDragDelta(object sender, DragDeltaEventArgs e)
{
Trace.TraceInformation($"LowerThumbDragDelta: h={e.HorizontalChange}, v={e.VerticalChange}");
}

private void RangeSlider_OnUpperThumbDragCompleted(object sender, DragCompletedEventArgs e)
{
Trace.TraceInformation("UpperThumbDragCompleted");
}

private void RangeSlider_OnCentralThumbDragStarted(object sender, DragStartedEventArgs e)
{
Trace.TraceInformation("CentralThumbDragStarted");
}

private void RangeSlider_OnCentralThumbDragDelta(object sender, DragDeltaEventArgs e)
{
Trace.TraceInformation($"CentralThumbDragDelta: h={e.HorizontalChange}, v={e.VerticalChange}");
}

private void RangeSlider_OnCentralThumbDragCompleted(object sender, DragCompletedEventArgs e)
{
Trace.TraceInformation("CentralThumbDragCompleted");
}
}
}
26 changes: 0 additions & 26 deletions src/MahApps.Metro/Controls/RangeParameterChangedEventArgs.cs

This file was deleted.

80 changes: 66 additions & 14 deletions src/MahApps.Metro/Controls/RangeSelectionChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,85 @@
using System;
using System.Windows;

namespace MahApps.Metro.Controls
{
/// <summary>
/// Event arguments created for the RangeSlider's SelectionChanged event.
/// <see cref="RangeSlider"/>
/// This delegate must used by handlers of the RangeSelectionChangedEvent event.
/// </summary>
public class RangeSelectionChangedEventArgs : RoutedEventArgs
/// <param name="sender">The current element along the event's route.</param>
/// <param name="e">The event arguments containing additional information about the event.</param>
/// <returns>Nothing.</returns>
public delegate void RangeSelectionChangedEventHandler<T>(object sender, RangeSelectionChangedEventArgs<T> e);

/// <summary>
/// This RangeSelectionChangedEventArgs class contains old and new value when
/// RangeSelectionChanged is raised.
/// </summary>
/// <seealso cref="RoutedEventArgs" />
/// <typeparam name="T"></typeparam>
public class RangeSelectionChangedEventArgs<T> : RoutedEventArgs
{
/// <summary>
/// The value of the new range's beginning.
/// Return the old lower value.
/// </summary>
public double NewLowerValue { get; set; }
public T OldLowerValue { get; }

/// <summary>
/// The value of the new range's ending.
/// Return the new lower value.
/// </summary>
public double NewUpperValue { get; set; }
public T NewLowerValue { get; }

public double OldLowerValue { get; set; }
/// <summary>
/// Return the old upper value.
/// </summary>
public T OldUpperValue { get; }

public double OldUpperValue { get; set; }
/// <summary>
/// Return the new upper value.
/// </summary>
public T NewUpperValue { get; }

internal RangeSelectionChangedEventArgs(double newLowerValue, double newUpperValue, double oldLowerValue, double oldUpperValue)
/// <summary>
/// This is an instance constructor for the RangeSelectionChangedEventArgs class.
/// </summary>
/// <param name="oldLowerValue">The old lower property value</param>
/// <param name="newLowerValue">The new lower property value</param>
/// <param name="oldUpperValue">The old upper property value</param>
/// <param name="newUpperValue">The new upper property value</param>
public RangeSelectionChangedEventArgs(T oldLowerValue, T newLowerValue, T oldUpperValue, T newUpperValue)
{
this.OldLowerValue = oldLowerValue;
this.NewLowerValue = newLowerValue;
this.OldUpperValue = oldUpperValue;
this.NewUpperValue = newUpperValue;
}

/// <summary>
/// This is an instance constructor for the RoutedPropertyChangedEventArgs class.
/// It is constructed with a reference to the event being raised.
/// </summary>
/// <param name="oldLowerValue">The old lower property value</param>
/// <param name="newLowerValue">The new lower property value</param>
/// <param name="oldUpperValue">The old upper property value</param>
/// <param name="newUpperValue">The new upper property value</param>
/// <param name="routedEvent">RoutedEvent</param>
public RangeSelectionChangedEventArgs(T oldLowerValue, T newLowerValue, T oldUpperValue, T newUpperValue, RoutedEvent routedEvent)
: this(oldLowerValue, newLowerValue, oldUpperValue, newUpperValue)
{
this.RoutedEvent = routedEvent;
}

/// <summary>
/// This method is used to perform the proper type casting in order to
/// call the type-safe RoutedPropertyChangedEventHandler delegate for the IsCheckedChangedEvent event.
/// </summary>
/// <param name="genericHandler">The handler to invoke.</param>
/// <param name="genericTarget">The current object along the event's route.</param>
/// <returns>Nothing.</returns>
protected override void InvokeEventHandler(Delegate genericHandler, object genericTarget)
{
NewLowerValue = newLowerValue;
NewUpperValue = newUpperValue;
OldLowerValue = oldLowerValue;
OldUpperValue = oldUpperValue;
var handler = (RangeSelectionChangedEventHandler<T>)genericHandler;
handler(genericTarget, this);
}
}
}
Loading

0 comments on commit b2455b5

Please # to comment.