Skip to content

Simplify and modernize WPF sample #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions samples/todoapp/TodoApp.WPF/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TodoApp.WPF"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
StartupUri="MainWindow.xaml"
ThemeMode="System">
<Application.Resources />
</Application>
32 changes: 0 additions & 32 deletions samples/todoapp/TodoApp.WPF/Converters/BooleanToImageConverter.cs

This file was deleted.

Binary file removed samples/todoapp/TodoApp.WPF/Images/completed.png
Binary file not shown.
Binary file removed samples/todoapp/TodoApp.WPF/Images/incomplete.png
Binary file not shown.
117 changes: 62 additions & 55 deletions samples/todoapp/TodoApp.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,73 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TodoApp.WPF"
xmlns:conv="clr-namespace:TodoApp.WPF.Converters"
xmlns:data="clr-namespace:TodoApp.WPF.Database"
mc:Ignorable="d"
Title="MainWindow" Height="420" Width="800"
ResizeMode="CanMinimize">
<Window.Resources>
<conv:BooleanToImageConverter x:Key="BooleanToImageConverter" />

<DataTemplate x:Key="CompletedIconTemplate">
<Image Width="16" Height="16" Source="{Binding Path=IsComplete, Converter={StaticResource BooleanToImageConverter}}" />
<DataTemplate x:Key="TaskItemTemplate" DataType="{x:Type data:TodoItem}">
<Grid>
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both TextBlock elements inside the Grid may be visible simultaneously when IsComplete is false. Consider adding a Visibility binding (e.g., using an inverse BooleanToVisibility converter) on the second TextBlock so that only the appropriate icon is shown based on the task's completion state.

Copilot uses AI. Check for mistakes.

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}" />
<Grid Grid.Column="1" Width="75">
<TextBlock FontFamily="Segoe Fluent Icons,Segoe MDL2 Assets" Text="&#xEC61;" Visibility="{Binding Path=IsComplete, Converter={StaticResource BooleanToVisibilityConverter}}" />
<TextBlock FontFamily="Segoe Fluent Icons,Segoe MDL2 Assets" Text="&#xEA3A;" />
</Grid>
</Grid>
</DataTemplate>
</Window.Resources>

<StackPanel Margin="10">
<!-- List View-->
<GroupBox Header="Tasks" Height="300">
<StackPanel>
<ListView
x:Name="TodoListView"
ItemsSource="{Binding Items}"
Height="300"
Margin="5"
VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn Header="Title" Width="650" DisplayMemberBinding="{Binding Title}"/>
<GridViewColumn Header="Completed" Width="75" CellTemplate="{StaticResource CompletedIconTemplate}"/>
</GridView>
</ListView.View>
<ListView.Resources>
<Style TargetType="ListViewItem">
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_DoubleClickEventHandler" />
</Style>
</ListView.Resources>
</ListView>
</StackPanel>
</GroupBox>

<GroupBox Header="Add Task">
<StackPanel Margin="5">
<DockPanel Height="26">
<TextBox x:Name="NewTodoItemTitle"
Width="560"
HorizontalAlignment="Left"
Margin="5,0,5,0"
Text="{Binding AddItemTitle, Mode=TwoWay}"
VerticalContentAlignment="Center"/>
<Button x:Name="AddTodoItemButton"
Width="75"
HorizontalAlignment="Right"
Content="Add"
Margin="5,0,5,0"
Command="{Binding AddItemCommand}"/>
<Button x:Name="RefreshTodoItemsButton"
Width="75"
HorizontalAlignment="Right"
Margin="5,0,5,0"
Content="Refresh"
Command="{Binding RefreshItemsCommand}"/>
</DockPanel>
</StackPanel>
</GroupBox>
</StackPanel>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<!-- Title -->
<TextBlock Margin="10" Style="{StaticResource SubtitleTextBlockStyle}" Text="Tasks" />
<!-- List View-->
<ListView x:Name="TodoListView"
Grid.Row="1"
Margin="5"
ItemTemplate="{StaticResource TaskItemTemplate}"
ItemsSource="{Binding Items}">
<ListView.Resources>
<Style BasedOn="{StaticResource {x:Type ListViewItem}}" TargetType="ListViewItem">
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_DoubleClickEventHandler" />
</Style>
</ListView.Resources>
</ListView>
<!-- Buttom -->
<Grid Grid.Row="2" Height="36">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBox x:Name="NewTodoItemTitle"
HorizontalAlignment="Stretch"
Margin="5,0,5,0"
Text="{Binding AddItemTitle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center"/>
<Button x:Name="AddTodoItemButton"
Grid.Column="1"
Width="75"
HorizontalAlignment="Right"
Content="Add"
Margin="5,0,5,0"
IsDefault="True"
Command="{Binding AddItemCommand}"/>
<Button x:Name="RefreshTodoItemsButton"
Grid.Column="2"
Width="75"
HorizontalAlignment="Right"
Margin="5,0,5,0"
Content="Refresh"
Command="{Binding RefreshItemsCommand}"/>
</Grid>
</Grid>
</Window>
10 changes: 0 additions & 10 deletions samples/todoapp/TodoApp.WPF/TodoApp.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<None Remove="Images\completed.png" />
<None Remove="Images\incomplete.png" />
</ItemGroup>

<ItemGroup>
<Resource Include="Images\completed.png" />
<Resource Include="Images\incomplete.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="CommunityToolkit.Datasync.Client" Version="9.0.2" />
Expand Down