-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainViewModel.cs
More file actions
92 lines (81 loc) · 2.74 KB
/
MainViewModel.cs
File metadata and controls
92 lines (81 loc) · 2.74 KB
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
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using System.Runtime.CompilerServices;
using System.Globalization;
using Microsoft.Maui.Controls;
namespace JSGradesMini;
public class MainViewModel : INotifyPropertyChanged
{
public ObservableCollection<Subject> Subjects { get; set; }
public MainViewModel()
{
Subjects = new ObservableCollection<Subject>
{
new Subject
{
Name = "Human-AI Interaction Design",
Percentage = 74,
Assessments = new ObservableCollection<Assessment>
{
new Assessment { Title = "Essay", DueDate = "2024-01-15", Weight = 40 },
new Assessment { Title = "Project", DueDate = "2024-03-10", Weight = 60 }
}
},
new Subject
{
Name = "Algorithmic Game Theory",
Percentage = 24,
Assessments = new ObservableCollection<Assessment>
{
new Assessment { Title = "Report", DueDate = "2024-02-20", Weight = 50 },
new Assessment { Title = "Exam", DueDate = "2024-04-25", Weight = 50 }
}
}
};
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class Subject
{
public string Name { get; set; } = string.Empty;
public int Percentage { get; set; }
public ObservableCollection<Assessment>? Assessments { get; set; }
private bool _isExpanded;
public bool IsExpanded
{
get => _isExpanded;
set
{
_isExpanded = value;
OnPropertyChanged(nameof(IsExpanded));
}
}
public ICommand ToggleExpandCommand { get; }
public Subject()
{
ToggleExpandCommand = new Command(() =>
{
// Trigger the expand/collapse action
IsExpanded = !IsExpanded;
// Show a modal alert to confirm the command is firing
Application.Current.MainPage.DisplayAlert("Expanded", IsExpanded ? "Expanded" : "Collapsed", "OK");
});
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class Assessment
{
public string Title { get; set; } = string.Empty;
public string DueDate { get; set; } = string.Empty;
public double Weight { get; set; } = 0.0;
}