-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMainPage.xaml.cs
80 lines (73 loc) · 3.23 KB
/
MainPage.xaml.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
using DevExpress.Data.Browsing.Design;
using DevExpress.Maui.CollectionView;
using System.Collections;
using DevExpress.Maui.Core;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
namespace CollectionViewLongTapExamp {
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
TitleAreaColor = ThemeColor.Primary;
}
public ThemeColor TitleAreaColor {
get { return (ThemeColor)GetValue(TitleAreaColorProperty); }
set { SetValue(TitleAreaColorProperty, value); }
}
public static readonly BindableProperty TitleAreaColorProperty = BindableProperty.Create("TitleAreaColor", typeof(ThemeColor), typeof(MainPage));
private void DXCollectionView_LongPress(object sender, CollectionViewGestureEventArgs e) {
EnableMultipleSelectionMode();
collectionView.SelectedItems = new List<object>() { e.Item };
}
private void CollectionViewSelectionChanged(object sender, CollectionViewSelectionChangedEventArgs e) {
int selectionCount = ((IList)collectionView.SelectedItems).Count;
if (selectionCount == 0)
DisableMultipleSelectionMode();
else {
selectionLabel.Text = selectionCount.ToString();
}
}
void EnableMultipleSelectionMode() {
collectionView.SelectionMode = SelectionMode.Multiple;
defaultTitle.IsVisible = false;
multipleSelectionPanel.IsVisible = true;
HapticFeedback.Default.Perform(HapticFeedbackType.LongPress);
}
void DisableMultipleSelectionMode() {
collectionView.SelectionMode = SelectionMode.None;
defaultTitle.IsVisible = true;
multipleSelectionPanel.IsVisible = false;
}
private void SelectAllButtonClick(object sender, EventArgs e) {
List<object> newSelectedItems = new List<object>();
foreach (var item in (IList)collectionView.ItemsSource)
newSelectedItems.Add(item);
collectionView.SelectedItems = newSelectedItems;
}
private void CancelButtonClick(object sender, EventArgs e) {
DisableMultipleSelectionMode();
}
}
public class SelectableItem : ContentView {
public bool IsSelected {
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}
public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create("IsSelected", typeof(bool), typeof(SelectableItem));
}
public class TitleViewFix : Grid {
bool isMeasured;
protected override Size MeasureOverride(double widthConstraint, double heightConstraint) {
isMeasured = true;
return base.MeasureOverride(widthConstraint, heightConstraint);
}
protected override Size ArrangeOverride(Rect bounds) {
if(!isMeasured)
Measure(bounds.Width, double.PositiveInfinity, MeasureFlags.None);
if (bounds.Height == 0)
bounds.Height = DesiredSize.Height + 12;
return base.ArrangeOverride(bounds);
}
}
}