Repository navigation
Expand file tree
/
Copy pathGestureUnlockExample.xaml.cs
More file actions
80 lines (73 loc) · 2.49 KB
/
Copy pathGestureUnlockExample.xaml.cs
File metadata and controls
80 lines (73 loc) · 2.49 KB
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
77
78
79
80
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFDevelopers.Controls;
using WPFDevelopers.Samples.Helpers;
using WPFDevelopers.Samples;
namespace WPFDevelopers.Sample.ExampleViews
{
/// <summary>
/// GestureUnlockExample.xaml 的交互逻辑
/// </summary>
public partial class GestureUnlockExample : UserControl
{
private string _password = "0426";
private enum GestureUnlockType
{
Unlock1,
Unlock2
}
public GestureUnlockExample()
{
InitializeComponent();
SampleLanguageManager.Instance.RegisterExampleView(this);
}
private void HandleGestureUnlock(string pwd, GestureUnlockType unlockType)
{
if (pwd.Length < 4)
{
SetControlState(unlockType, ControlState.Error);
Toast.PushDesktop(
SampleLanguageManager.Instance.TranslateText("手势错误,最少 4 个节点!"),
ToastImage.Error,
true);
return;
}
if (pwd != _password)
{
SetControlState(unlockType, ControlState.Error);
Toast.PushDesktop(
SampleLanguageManager.Instance.TranslateText("手势错误,请重新解锁!"),
ToastImage.Error,
true);
return;
}
SetControlState(unlockType, ControlState.Success);
Toast.Push(
SampleLanguageManager.Instance.TranslateText("手势正确!"),
ToastImage.Success,
true);
}
private void SetControlState(GestureUnlockType unlockType, ControlState state)
{
if (unlockType == GestureUnlockType.Unlock1)
{
myGestureUnlock.State = state;
}
else if (unlockType == GestureUnlockType.Unlock2)
{
myGestureUnlock2.State = state;
}
}
private void GestureCompleted(object sender, RoutedEventArgs e)
{
var unlock = e.OriginalSource as GestureUnlock;
HandleGestureUnlock(unlock?.Password ?? string.Empty, GestureUnlockType.Unlock1);
}
public ICommand CompletedCommand => new RelayCommand(param =>
{
var pwd = param.ToString();
HandleGestureUnlock(pwd, GestureUnlockType.Unlock2);
});
}
}