-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathMultipleListView.cs
89 lines (77 loc) · 2.71 KB
/
MultipleListView.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
79
80
81
82
83
84
85
86
87
88
89
//
// Copyright Fela Ameghino 2015-2025
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Telegram.Controls
{
public partial class MultipleListView : ListView
{
protected override DependencyObject GetContainerForItemOverride()
{
return new MultipleListViewItem(this);
}
}
public partial class MultipleListViewItem : TableListViewItem
{
private readonly ListViewBase _owner;
private readonly bool _multi;
private bool _enabled;
private bool _selected;
public MultipleListViewItem(ListViewBase owner, bool multi = true)
{
_owner = owner;
_multi = multi;
_enabled = owner.SelectionMode == ListViewSelectionMode.Multiple;
DefaultStyleKey = typeof(MultipleListViewItem);
}
public bool IsSingle => !_multi;
public void UpdateState(bool selected)
{
var enabled = _owner.SelectionMode == ListViewSelectionMode.Multiple;
if (enabled == _enabled && _selected == selected)
{
return;
}
if (ContentTemplateRoot is IMultipleElement test)
{
_selected = selected;
_enabled = enabled;
test.UpdateState(selected, true, enabled);
}
}
}
public interface IMultipleElement
{
void UpdateState(bool selected, bool animate, bool multiple);
}
public partial class MultipleVisualStateManager : VisualStateManager
{
private bool _multi;
protected override bool GoToStateCore(Control control, FrameworkElement templateRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions)
{
var selector = control as MultipleListViewItem;
if (selector == null)
{
return false;
}
if (group.Name == "MultiSelectStates")
{
_multi = stateName == "MultiSelectEnabled";
selector.UpdateState((_multi || selector.IsSingle) && selector.IsSelected);
}
else if ((_multi || selector.IsSingle) && stateName.EndsWith("Selected"))
{
stateName = stateName.Replace("Selected", string.Empty);
if (string.IsNullOrEmpty(stateName))
{
stateName = "Normal";
}
}
return base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions);
}
}
}