Complete TodoApp sample application with: - App.xaml/cs: Colors and styles for light/dark themes - TodoListPage: Task list with theme toggle switch - NewTodoPage: Form to create new tasks - TodoDetailPage: Edit task details with delete option - TodoItem.cs/TodoService.cs: Data model and service - SVG icons for save, delete, and add actions Theme switching via toggle on main page applies app-wide. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
using System;
|
|
using Microsoft.Maui.ApplicationModel;
|
|
using Microsoft.Maui.Controls;
|
|
|
|
namespace TodoApp;
|
|
|
|
public partial class TodoListPage : ContentPage
|
|
{
|
|
private readonly TodoService _service = TodoService.Instance;
|
|
private bool _isNavigating;
|
|
|
|
public TodoListPage()
|
|
{
|
|
InitializeComponent();
|
|
TodoCollectionView.ItemsSource = _service.Todos;
|
|
UpdateStats();
|
|
ThemeSwitch.IsToggled = Application.Current?.UserAppTheme == AppTheme.Dark;
|
|
}
|
|
|
|
protected override void OnAppearing()
|
|
{
|
|
base.OnAppearing();
|
|
_isNavigating = false;
|
|
_service.RefreshIndexes();
|
|
TodoCollectionView.ItemsSource = null;
|
|
TodoCollectionView.ItemsSource = _service.Todos;
|
|
UpdateStats();
|
|
}
|
|
|
|
private void OnThemeToggled(object? sender, ToggledEventArgs e)
|
|
{
|
|
if (Application.Current != null)
|
|
{
|
|
Application.Current.UserAppTheme = e.Value ? AppTheme.Dark : AppTheme.Light;
|
|
// Refresh to apply theme
|
|
var items = TodoCollectionView.ItemsSource;
|
|
TodoCollectionView.ItemsSource = null;
|
|
TodoCollectionView.ItemsSource = items;
|
|
}
|
|
}
|
|
|
|
private async void OnAddClicked(object? sender, EventArgs e)
|
|
{
|
|
await Navigation.PushAsync(new NewTodoPage());
|
|
}
|
|
|
|
private async void OnItemTapped(object? sender, TappedEventArgs e)
|
|
{
|
|
if (_isNavigating || e.Parameter is not TodoItem todoItem)
|
|
return;
|
|
|
|
_isNavigating = true;
|
|
try
|
|
{
|
|
await Navigation.PushAsync(new TodoDetailPage(todoItem));
|
|
}
|
|
catch
|
|
{
|
|
_isNavigating = false;
|
|
}
|
|
}
|
|
|
|
private void UpdateStats()
|
|
{
|
|
int completed = _service.CompletedCount;
|
|
int total = _service.TotalCount;
|
|
StatsLabel.Text = total == 0 ? "" : $"Tasks: {completed} of {total}";
|
|
}
|
|
}
|