Last active
February 7, 2017 01:22
-
-
Save JerryNixon/218f7df7cbff3579540d86112d715c07 to your computer and use it in GitHub Desktop.
For the way of the sub.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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