BradleyUffner

Untitled

Jan 15th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls.Primitives;
  8. using System.Windows.Interactivity;
  9.  
  10. namespace AgentOctal.WpfLib.Behaviors
  11. {
  12. public class ThumbLink : Behavior<Thumb>
  13. {
  14. protected override void OnAttached()
  15. {
  16. AssociatedObject.DragDelta += AssociatedObject_DragDelta;
  17. }
  18.  
  19. protected override void OnDetaching()
  20. {
  21. AssociatedObject.DragDelta -= AssociatedObject_DragDelta;
  22. }
  23.  
  24. private void AssociatedObject_DragDelta(object sender, DragDeltaEventArgs e)
  25. {
  26. var delta = new ThumbDeltaInfo(e.HorizontalChange, e.VerticalChange);
  27. ThumbDelta = delta;
  28. e.Handled = true;
  29. }
  30.  
  31. public ThumbDeltaInfo ThumbDelta
  32. {
  33. get { return (ThumbDeltaInfo)GetValue(ThumbDeltaProperty); }
  34. set { SetValue(ThumbDeltaProperty, value); }
  35. }
  36.  
  37. public static readonly DependencyProperty ThumbDeltaProperty =
  38. DependencyProperty.Register("ThumbDelta", typeof(ThumbDeltaInfo), typeof(ThumbLink),
  39. new FrameworkPropertyMetadata(defaultValue: default(ThumbDeltaInfo),
  40. flags: FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
  41.  
  42. public struct ThumbDeltaInfo
  43. {
  44. public ThumbDeltaInfo(double horizontalChange, double verticalChange)
  45. {
  46. HorizontalChange = horizontalChange;
  47. VerticalChange = verticalChange;
  48. }
  49.  
  50. public double HorizontalChange;
  51. public double VerticalChange;
  52.  
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment