-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
SwipeItemView.cs
78 lines (63 loc) · 2.57 KB
/
SwipeItemView.cs
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
#nullable disable
using System;
using System.ComponentModel;
using System.Windows.Input;
namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/SwipeItemView.xml" path="Type[@FullName='Microsoft.Maui.Controls.SwipeItemView']/Docs/*" />
[ContentProperty(nameof(Content))]
public partial class SwipeItemView : ContentView, Controls.ISwipeItem, Maui.ISwipeItemView
{
/// <summary>Bindable property for <see cref="Command"/>.</summary>
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(SwipeItemView), null,
propertyChanging: (bo, o, n) => ((SwipeItemView)bo).OnCommandChanging(),
propertyChanged: (bo, o, n) => ((SwipeItemView)bo).OnCommandChanged());
/// <summary>Bindable property for <see cref="CommandParameter"/>.</summary>
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(SwipeItemView), null,
propertyChanged: (bo, o, n) => ((SwipeItemView)bo).OnCommandParameterChanged());
/// <include file="../../docs/Microsoft.Maui.Controls/SwipeItemView.xml" path="//Member[@MemberName='Command']/Docs/*" />
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
/// <include file="../../docs/Microsoft.Maui.Controls/SwipeItemView.xml" path="//Member[@MemberName='CommandParameter']/Docs/*" />
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public event EventHandler<EventArgs> Invoked;
/// <include file="../../docs/Microsoft.Maui.Controls/SwipeItemView.xml" path="//Member[@MemberName='OnInvoked']/Docs/*" />
[EditorBrowsable(EditorBrowsableState.Never)]
public void OnInvoked()
{
if (Command != null && Command.CanExecute(CommandParameter))
Command.Execute(CommandParameter);
Invoked?.Invoke(this, EventArgs.Empty);
}
void OnCommandChanged()
{
IsEnabled = Command?.CanExecute(CommandParameter) ?? true;
if (Command == null)
return;
Command.CanExecuteChanged += OnCommandCanExecuteChanged;
}
void OnCommandChanging()
{
if (Command == null)
return;
Command.CanExecuteChanged -= OnCommandCanExecuteChanged;
}
void OnCommandParameterChanged()
{
if (Command == null)
return;
IsEnabled = Command.CanExecute(CommandParameter);
}
void OnCommandCanExecuteChanged(object sender, EventArgs eventArgs)
{
IsEnabled = Command.CanExecute(CommandParameter);
}
}
}