Skip to content

Commit e4faeea

Browse files
committed
Create GestureUnlock
1 parent 41fd013 commit e4faeea

File tree

13 files changed

+599
-2
lines changed

13 files changed

+599
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<UserControl
2+
x:Class="WPFDevelopers.Sample.ExampleViews.GestureUnlockExample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
10+
d:DesignHeight="450"
11+
d:DesignWidth="800"
12+
mc:Ignorable="d">
13+
<controls:CodeViewer Header="{Binding NavigateMenuItem.Name}">
14+
<TabControl TabStripPlacement="Bottom">
15+
<TabItem Header="Event">
16+
<wd:GestureUnlock
17+
x:Name="myGestureUnlock"
18+
wd:ElementHelper.CornerRadius="5"
19+
GestureCompleted="GestureCompleted">
20+
<wd:GestureUnlock.Background>
21+
<ImageBrush ImageSource="pack://application:,,,/WPFDevelopers.Samples;component/Resources/Images/Chat/Right.jpg" />
22+
</wd:GestureUnlock.Background>
23+
</wd:GestureUnlock>
24+
</TabItem>
25+
<TabItem Header="Command">
26+
<TabItem.Resources>
27+
<Style BasedOn="{StaticResource WD.GestureItem}" TargetType="wd:GestureItem">
28+
<Setter Property="BorderBrush" Value="Yellow" />
29+
</Style>
30+
</TabItem.Resources>
31+
<wd:GestureUnlock
32+
x:Name="myGestureUnlock2"
33+
Width="400"
34+
Height="500"
35+
wd:ElementHelper.CornerRadius="10"
36+
GestureCompletedCommand="{Binding GestureCompletedCommand}">
37+
<wd:GestureUnlock.Background>
38+
<ImageBrush ImageSource="pack://application:,,,/WPFDevelopers.Samples;component/Resources/Images/IconicThumbnail/LcupqA.jpg" />
39+
</wd:GestureUnlock.Background>
40+
</wd:GestureUnlock>
41+
</TabItem>
42+
</TabControl>
43+
<controls:CodeViewer.SourceCodes>
44+
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/GestureUnlockExample.xaml" CodeType="Xaml" />
45+
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/GestureUnlockExample.xaml.cs" CodeType="CSharp" />
46+
</controls:CodeViewer.SourceCodes>
47+
</controls:CodeViewer>
48+
</UserControl>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
using System.Windows.Input;
4+
using WPFDevelopers.Controls;
5+
using WPFDevelopers.Samples.Helpers;
6+
7+
namespace WPFDevelopers.Sample.ExampleViews
8+
{
9+
/// <summary>
10+
/// GestureUnlockExample.xaml 的交互逻辑
11+
/// </summary>
12+
public partial class GestureUnlockExample : UserControl
13+
{
14+
private string _password = "0426";
15+
private enum GestureUnlockType
16+
{
17+
Unlock1,
18+
Unlock2
19+
}
20+
public GestureUnlockExample()
21+
{
22+
InitializeComponent();
23+
DataContext = this;
24+
}
25+
26+
private void HandleGestureUnlock(string pwd, GestureUnlockType unlockType)
27+
{
28+
if (pwd.Length < 4)
29+
{
30+
SetGestureState(unlockType, GestureState.Error);
31+
Message.PushDesktop("手势错误,最少 4 个节点!", MessageBoxImage.Error, true);
32+
return;
33+
}
34+
35+
if (pwd != _password)
36+
{
37+
SetGestureState(unlockType, GestureState.Error);
38+
Message.PushDesktop("手势错误,请重新解锁!", MessageBoxImage.Error, true);
39+
return;
40+
}
41+
42+
SetGestureState(unlockType, GestureState.Success);
43+
Message.Push("手势正确!", MessageBoxImage.Information, true);
44+
}
45+
46+
private void SetGestureState(GestureUnlockType unlockType, GestureState state)
47+
{
48+
if (unlockType == GestureUnlockType.Unlock1)
49+
{
50+
myGestureUnlock.State = state;
51+
}
52+
else if (unlockType == GestureUnlockType.Unlock2)
53+
{
54+
myGestureUnlock2.State = state;
55+
}
56+
}
57+
58+
private void GestureCompleted(object sender, RoutedEventArgs e)
59+
{
60+
var pwd = e.OriginalSource.ToString();
61+
HandleGestureUnlock(pwd, GestureUnlockType.Unlock1);
62+
}
63+
64+
public ICommand GestureCompletedCommand => new RelayCommand(param =>
65+
{
66+
var pwd = param.ToString();
67+
HandleGestureUnlock(pwd, GestureUnlockType.Unlock2);
68+
});
69+
}
70+
}

src/WPFDevelopers.Samples.Shared/ExampleViews/MessageExample.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
Content="Long Message"
5656
Style="{StaticResource WD.SuccessPrimaryButton}"
5757
Tag="Long" />
58+
<Button
59+
Click="AddButton_Click"
60+
Content="IntPtr Window"
61+
Style="{StaticResource WD.SuccessPrimaryButton}"
62+
Tag="IntPtr" />
5863
<Button Click="BtnClear_Click" Content="Clear" />
5964
</UniformGrid>
6065
</GroupBox>

src/WPFDevelopers.Samples.Shared/ExampleViews/MessageExample.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Controls;
4+
using System.Windows.Interop;
45
using WPFDevelopers.Controls;
56

67
namespace WPFDevelopers.Samples.ExampleViews
@@ -42,6 +43,11 @@ private void AddButton_Click(object sender, RoutedEventArgs e)
4243
case "Question":
4344
Message.Push("This is a question message", MessageBoxImage.Question);
4445
break;
46+
case "IntPtr":
47+
Window parentWindow = Window.GetWindow(this);
48+
IntPtr windowHandle = new WindowInteropHelper(parentWindow).Handle;
49+
Message.Push(windowHandle, "This is a question message", MessageBoxImage.Question);
50+
break;
4551
default:
4652
Message.Push("这是一条很长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长消息", MessageBoxImage.Information);
4753
break;

src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public enum MenuEnum
9494
Tag,
9595
NavScrollPanel,
9696
IconicThumbnail,
97+
GestureUnlock,
9798
VirtualizingWrapPanel,
9899
AcrylicBlur,
99100
TaskbarInfo

src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ void MenuItemSelection(string _menuName)
388388
ControlPanel = new IconicThumbnailExample();
389389
new IconicThumbnailWindowExample().MaskShowDialog();
390390
break;
391+
case MenuEnum.GestureUnlock:
392+
ControlPanel = new GestureUnlockExample();
393+
break;
391394
case MenuEnum.VirtualizingWrapPanel:
392395
ControlPanel = new VirtualizingWrapPanel();
393396
new VirtualizingWrapPanelExample().MaskShowDialog();

src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@
328328
<Compile Include="$(MSBuildThisFileDirectory)ExampleViews\NavScrollPanel\ShortcutKeys.xaml.cs">
329329
<DependentUpon>ShortcutKeys.xaml</DependentUpon>
330330
</Compile>
331+
<Compile Include="$(MSBuildThisFileDirectory)ExampleViews\GestureUnlockExample.xaml.cs">
332+
<DependentUpon>GestureUnlockExample.xaml</DependentUpon>
333+
</Compile>
331334
<Compile Include="$(MSBuildThisFileDirectory)ExampleViews\TagExample.xaml.cs">
332335
<DependentUpon>TagExample.xaml</DependentUpon>
333336
</Compile>
@@ -906,6 +909,10 @@
906909
<Generator>MSBuild:Compile</Generator>
907910
<SubType>Designer</SubType>
908911
</Page>
912+
<Page Include="$(MSBuildThisFileDirectory)ExampleViews\GestureUnlockExample.xaml">
913+
<Generator>MSBuild:Compile</Generator>
914+
<SubType>Designer</SubType>
915+
</Page>
909916
<Page Include="$(MSBuildThisFileDirectory)ExampleViews\TagExample.xaml">
910917
<Generator>MSBuild:Compile</Generator>
911918
<SubType>Designer</SubType>

src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<Resource Include="..\WPFDevelopers.Samples.Shared\Controls\BubblleControl\BubblleCanvas.cs" Link="Controls\BubblleControl\BubblleCanvas.cs" />
161161
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\NavScrollPanelExample.xaml.cs" Link="ExampleViews\NavScrollPanelExample.xaml.cs" DependentUpon="NavScrollPanelExample.xaml" />
162162
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\IconicThumbnailWindowExample.xaml.cs" Link="ExampleViews\IconicThumbnailWindowExample.xaml.cs" DependentUpon="IconicThumbnailWindowExample.xaml" />
163+
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\GestureUnlockExample.xaml.cs" Link="ExampleViews\GestureUnlockExample.xaml.cs" DependentUpon="GestureUnlockExample.xaml" />
163164
</ItemGroup>
164165
<ItemGroup>
165166
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\AboutWindow.xaml">
@@ -546,5 +547,8 @@
546547
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\IconicThumbnailWindowExample.xaml">
547548
<Link>ExampleViews\IconicThumbnailWindowExample.xaml</Link>
548549
</Resource>
550+
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\GestureUnlockExample.xaml">
551+
<Link>ExampleViews\GestureUnlockExample.xaml</Link>
552+
</Resource>
549553
</ItemGroup>
550554
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace WPFDevelopers.Controls
5+
{
6+
public class GestureItem : Control
7+
{
8+
public static readonly DependencyProperty NumberProperty =
9+
DependencyProperty.Register("Number", typeof(int), typeof(GestureItem), new PropertyMetadata(0));
10+
11+
public static readonly DependencyProperty IsSelectedProperty =
12+
DependencyProperty.Register("IsSelected", typeof(bool), typeof(GestureItem), new PropertyMetadata(false));
13+
14+
static GestureItem()
15+
{
16+
DefaultStyleKeyProperty.OverrideMetadata(typeof(GestureItem),
17+
new FrameworkPropertyMetadata(typeof(GestureItem)));
18+
}
19+
20+
public int Number
21+
{
22+
get => (int) GetValue(NumberProperty);
23+
set => SetValue(NumberProperty, value);
24+
}
25+
26+
public bool IsSelected
27+
{
28+
get => (bool) GetValue(IsSelectedProperty);
29+
set => SetValue(IsSelectedProperty, value);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)