summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml.cs
blob: 737bb724559a30259296a3894c74334bca2391f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Xamarin.Forms;
using System;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	public partial class BehaviorsAndTriggers : ContentPage
	{	
		public BehaviorsAndTriggers ()
		{
			InitializeComponent ();
		}
	}

	[Preserve (AllMembers = true)]
	public class Throb : TriggerAction<VisualElement>
	{
		bool _horizontal;

		public Throb (bool horizontal)
		{
			_horizontal = horizontal;			
		}

		protected override async void Invoke (VisualElement sender)
		{
			for (var i=0;i<5;i++){
				await sender.TranslateTo (_horizontal ? -5:0,!_horizontal ? -5 : 0, 25);
				await sender.TranslateTo (_horizontal ? 5:0,!_horizontal ? 5: 0, 25);
			}
			await sender.TranslateTo (0, 0, 25);
		}	
	}

	[Preserve (AllMembers = true)]
	public class HThrob : Throb
	{
		[Preserve]
		public HThrob ()
			: base (true)
		{			
		}
	}

	[Preserve (AllMembers = true)]
	public class VThrob : Throb
	{
		public VThrob () : base (false)
		{			
		}
	}

	[Preserve (AllMembers = true)]
	public class StopItBehavior : Behavior<Button>
	{
		protected override void OnAttachedTo (Button bindable)
		{
			base.OnAttachedTo (bindable);
			bindable.Clicked += OnClicked;
		}

		protected override void OnDetachingFrom (Button bindable)
		{
			bindable.Clicked -= OnClicked;
			base.OnDetachingFrom (bindable);
		}

		void OnClicked (object sender, EventArgs e)
		{
			var button = (Button)sender;
			button.Text = "Don't do this again";
			button.IsEnabled = false;
		}
	}	
}