-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewModel.cs
103 lines (84 loc) · 3.09 KB
/
ViewModel.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
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using DevExpress.Maui.Editors;
namespace CalendarExample {
public class ViewModel : INotifyPropertyChanged {
DateTime displayDate;
DateTime? selectedDate;
DXCalendarViewType activeViewType;
bool isHolidaysAndObservancesListVisible;
IEnumerable<SpecialDate> specialDates;
public ViewModel() {
DisplayDate = DateTime.Today;
UpdateHolidaysAndObservancesListVisible();
}
public IEnumerable<SpecialDate> SpecialDates {
get => this.specialDates;
set {
if (this.specialDates == value)
return;
this.specialDates = value;
NotifyPropertyChanged();
}
}
public DateTime DisplayDate {
get => this.displayDate;
set {
if (this.displayDate == value)
return;
this.displayDate = value;
UpdateCurrentCalendarIfNeeded();
SpecialDates = USCalendar.GetSpecialDatesForMonth(DisplayDate.Month);
NotifyPropertyChanged();
}
}
public DateTime? SelectedDate {
get => this.selectedDate;
set {
if (this.selectedDate == value)
return;
this.selectedDate = value;
NotifyPropertyChanged();
}
}
public DXCalendarViewType ActiveViewType {
get => this.activeViewType;
set {
if (this.activeViewType == value)
return;
this.activeViewType = value;
UpdateHolidaysAndObservancesListVisible();
NotifyPropertyChanged();
}
}
public bool IsHolidaysAndObservancesListVisible {
get => this.isHolidaysAndObservancesListVisible;
set {
if (this.isHolidaysAndObservancesListVisible == value)
return;
this.isHolidaysAndObservancesListVisible = value;
NotifyPropertyChanged();
}
}
USCalendar USCalendar { get; set; }
public SpecialDate TryFindSpecialDate(DateTime date) {
return SpecialDates.FirstOrDefault(x => x.Date == date);
}
void UpdateHolidaysAndObservancesListVisible() {
IsHolidaysAndObservancesListVisible = ActiveViewType == DXCalendarViewType.Month;
}
void UpdateCurrentCalendarIfNeeded() {
if (USCalendar == null || USCalendar.Year != DisplayDate.Year)
USCalendar = new USCalendar(DisplayDate.Year);
}
public event PropertyChangedEventHandler PropertyChanged;
void NotifyPropertyChanged([CallerMemberName] string propertyName = "") {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}