-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDatabasePage.xaml.cs
More file actions
59 lines (52 loc) · 1.66 KB
/
DatabasePage.xaml.cs
File metadata and controls
59 lines (52 loc) · 1.66 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
using EntglDb.Sample.Shared;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace EntglDb.Test.Maui;
public partial class DatabasePage : ContentPage
{
private readonly SampleDbContext _db;
public ObservableCollection<CollectionViewModel> Collections { get; } = new();
public ICommand RefreshCommand { get; }
public DatabasePage(SampleDbContext db)
{
InitializeComponent();
_db = db;
RefreshCommand = new Command(async () => await LoadCollections());
BindingContext = this;
}
protected override async void OnAppearing()
{
base.OnAppearing();
await LoadCollections();
}
private Task LoadCollections()
{
try
{
Collections.Clear();
Collections.Add(new CollectionViewModel { Name = "Users" });
Collections.Add(new CollectionViewModel { Name = "TodoLists" });
}
catch (Exception ex)
{
_ = DisplayAlert("Error", $"Failed to load collections: {ex.Message}", "OK");
}
finally
{
CollectionsRefreshView.IsRefreshing = false;
}
return Task.CompletedTask;
}
private async void OnCollectionSelected(object sender, SelectionChangedEventArgs e)
{
if (e.CurrentSelection.FirstOrDefault() is CollectionViewModel selected)
{
CollectionsCollectionView.SelectedItem = null; // Deselect
await Navigation.PushAsync(new CollectionPage(_db, selected.Name));
}
}
}
public class CollectionViewModel
{
public string Name { get; set; }
}