Skip to content

Instantly share code, notes, and snippets.

@JerryNixon
Last active February 7, 2017 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JerryNixon/218f7df7cbff3579540d86112d715c07 to your computer and use it in GitHub Desktop.
Save JerryNixon/218f7df7cbff3579540d86112d715c07 to your computer and use it in GitHub Desktop.
For the way of the sub.
public class ButtonEx : Button
{
public ButtonEx() : base()
{
ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.System;
ManipulationCompleted += (s, e) => ShouldExcuteCommand2(Math.Abs(e.Cumulative.Translation.X));
Tapped += (s, e) => ShouldExcuteCommand2(DateTime.Now);
}
private void ShouldExcuteCommand2(double distanceX)
{
if (distanceX > 16) ShouldExcuteCommand2(DateTime.Now);
}
private void ShouldExcuteCommand2(DateTime time)
{
var delta = DateDiff(lastExecute, time);
if (delta > TimeSpan.FromMilliseconds(500)) ExecuteCommand2();
}
private TimeSpan DateDiff(DateTime early, DateTime late) => late.Subtract(early);
DateTime lastExecute = DateTime.MinValue;
private void ExecuteCommand2()
{
lastExecute = DateTime.Now;
Command2?.Execute(CommandParameter);
}
public ICommand Command2
{
get { return (ICommand)GetValue(Command2Property); }
set { SetValue(Command2Property, value); }
}
public static readonly DependencyProperty Command2Property =
DependencyProperty.Register(nameof(Command2), typeof(ICommand),
typeof(ButtonEx), new PropertyMetadata(null));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment