Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Input;
  6. using Xamarin.Forms;
  7.  
  8. namespace DragViewSample
  9. {
  10. public partial class DraggableView : ContentView
  11. {
  12. public event EventHandler DragStart= delegate { };
  13. public event EventHandler DragEnd = delegate { };
  14.  
  15. public static readonly BindableProperty DragDirectionProperty = BindableProperty.Create(
  16. propertyName: "DragDirection",
  17. returnType: typeof(DragDirectionType),
  18. declaringType: typeof(DraggableView),
  19. defaultValue: DragDirectionType.All,
  20. defaultBindingMode: BindingMode.TwoWay);
  21.  
  22. public DragDirectionType DragDirection
  23. {
  24. get { return (DragDirectionType)GetValue(DragDirectionProperty); }
  25. set { SetValue(DragDirectionProperty, value); }
  26. }
  27.  
  28.  
  29. public static readonly BindableProperty DragModeProperty = BindableProperty.Create(
  30. propertyName: "DragMode",
  31. returnType: typeof(DragMode),
  32. declaringType: typeof(DraggableView),
  33. defaultValue: DragMode.LongPress,
  34. defaultBindingMode: BindingMode.TwoWay);
  35.  
  36. public DragMode DragMode
  37. {
  38. get { return (DragMode)GetValue(DragModeProperty); }
  39. set { SetValue(DragModeProperty, value); }
  40. }
  41.  
  42. public static readonly BindableProperty IsDraggingProperty = BindableProperty.Create(
  43. propertyName: "IsDragging",
  44. returnType: typeof(bool),
  45. declaringType: typeof(DraggableView),
  46. defaultValue: false,
  47. defaultBindingMode: BindingMode.TwoWay);
  48.  
  49. public bool IsDragging
  50. {
  51. get { return (bool)GetValue(IsDraggingProperty); }
  52. set { SetValue(IsDraggingProperty, value); }
  53. }
  54.  
  55. public static readonly BindableProperty RestorePositionCommandProperty = BindableProperty.Create(nameof(RestorePositionCommand), typeof(ICommand), typeof(DraggableView), default(ICommand), BindingMode.TwoWay, null, OnRestorePositionCommandPropertyChanged);
  56.  
  57. static void OnRestorePositionCommandPropertyChanged(BindableObject bindable, object oldValue, object newValue)
  58. {
  59. var source = bindable as DraggableView;
  60. if (source == null)
  61. {
  62. return;
  63. }
  64. source.OnRestorePositionCommandChanged();
  65. }
  66.  
  67. private void OnRestorePositionCommandChanged()
  68. {
  69. OnPropertyChanged("RestorePositionCommand");
  70. }
  71.  
  72. public ICommand RestorePositionCommand
  73. {
  74. get
  75. {
  76. return (ICommand)GetValue(RestorePositionCommandProperty);
  77. }
  78. set
  79. {
  80. SetValue(RestorePositionCommandProperty, value);
  81. }
  82. }
  83.  
  84. public void DragStarted()
  85. {
  86. DragStart(this, default(EventArgs));
  87. IsDragging = true;
  88. }
  89.  
  90. public void DragEnded()
  91. {
  92. IsDragging = false;
  93. DragEnd(this, default(EventArgs));
  94. }
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement