今天我們來將done功能給加入到我們的App裡,並順便筆記複習一下
修改一下我們的Todo\Pages\TodoPage.xaml
...
<VerticalStackLayout Margin="10">
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button Text="Go to Add Page" Clicked="ButtonClicked"/>
<CollectionView ItemsSource="{Binding Todos}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:TodoItemModel">
<Frame>
<HorizontalStackLayout Spacing="10" HorizontalOptions="Center">
<Label Text="{Binding Title}">
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding IsDone}"
Value="True">
<Setter Property="TextColor"
Value="Gray" />
</DataTrigger>
</Label.Triggers>
</Label>
<Button Text="Delete"
Command="{Binding Source={x:RelativeSource AncestorType={x:Type viewModels:TodoListViewModel}},Path=DeleteTodoCommand}"
CommandParameter="{Binding .}"/>
<Button Text="Edit"
Command="{Binding Source={x:RelativeSource AncestorType={x:Type viewModels:TodoListViewModel}},Path=EditTodoCommand}"
CommandParameter="{Binding .}"/>
</HorizontalStackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
...
並在Todo\Pages\AddTodoPage.xaml
加入我們的Done
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Todo.Models"
x:Class="Todo.AddTodoPage"
Title="AddTodoPage">
<VerticalStackLayout Padding="10">
<Label
Text="Add Todo"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Entry Placeholder="Add Todo" Text="{Binding TodoItem.Title}"/>
<CheckBox IsChecked="{Binding TodoItem.IsDone}" />
<Button Text="Add Todo Item" Command="{Binding AddUpdateTodoCommand}" />
</VerticalStackLayout>
</ContentPage>
接著進行測試
今天將Todo的done功能給加入,並且當完成時文字變灰色