File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace Desktop . Common ;
2+
3+ public interface ICloseable
4+ {
5+ void Close ( ) ;
6+ }
Original file line number Diff line number Diff line change 1+ using System . ComponentModel ;
2+ using System . Runtime . CompilerServices ;
3+
4+ namespace Desktop . Common ;
5+
6+ public abstract class ViewModelBase : INotifyPropertyChanged
7+ {
8+ public event PropertyChangedEventHandler ? PropertyChanged ;
9+
10+ protected virtual void OnPropertyChanged ( [ CallerMemberName ] string ? propertyName = null )
11+ {
12+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
13+ }
14+
15+ protected bool SetField < T > (
16+ ref T field ,
17+ T value ,
18+ [ CallerMemberName ] string ? propertyName = null )
19+ {
20+ if ( EqualityComparer < T > . Default . Equals ( field , value ) )
21+ return false ;
22+
23+ field = value ;
24+ OnPropertyChanged ( propertyName ) ;
25+
26+ return true ;
27+ }
28+ }
Original file line number Diff line number Diff line change 2828
2929 <ItemGroup >
3030 <PackageReference Include =" Microsoft.AspNet.WebApi.Client" Version =" 6.0.0" />
31- <PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 9.0.5" />
32- <PackageReference Include =" Microsoft.Extensions.DependencyInjection" Version =" 9.0.5" />
31+ <PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 9.0.5" />
32+ <PackageReference Include =" Microsoft.Extensions.DependencyInjection" Version =" 9.0.5" />
33+ <PackageReference Include =" MVVMToolkitExtensions.WPF" Version =" 1.0.5" />
3334 </ItemGroup >
3435
3536 <ItemGroup >
Original file line number Diff line number Diff line change 33 xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
44 xmlns : d =" http://schemas.microsoft.com/expression/blend/2008"
55 xmlns : mc =" http://schemas.openxmlformats.org/markup-compatibility/2006"
6+ xmlns : local =" clr-namespace:Desktop.Tasks"
67 mc : Ignorable =" d"
8+ x : Name =" TaskCreationWindow"
79 Title =" Task creation" Height =" 225" Width =" 400"
810 WindowStartupLocation =" CenterScreen" >
11+ <Window .DataContext>
12+ <local : TaskCreationViewModel />
13+ </Window .DataContext>
914 <Grid FocusManager.FocusedElement=" {Binding ElementName=Name}" >
1015 <Grid .RowDefinitions>
1116 <RowDefinition Height =" Auto" />
2126 VerticalAlignment =" Stretch" />
2227 <Button AutomationProperties.AutomationId=" SaveTask" Grid.Row=" 4" Content =" Add" HorizontalAlignment =" Right"
2328 IsDefault =" True"
24- Click =" SaveTask" />
29+ Click =" SaveTask"
30+ Command =" {Binding SaveTask }"
31+ CommandParameter =" {Binding ElementName=TaskCreationWindow}" />
2532 </Grid >
2633</Window >
Original file line number Diff line number Diff line change 11using System . Windows ;
2+ using Desktop . Common ;
23using Task = Desktop . Domain . Task ;
34
45namespace Desktop . Tasks ;
56
67using Task = Task ;
78
8- public partial class TaskCreation : Window
9+ public partial class TaskCreation : Window , ICloseable
910{
1011 public TaskCreation ( )
1112 {
@@ -17,6 +18,5 @@ public TaskCreation()
1718 private void SaveTask ( object sender , RoutedEventArgs e )
1819 {
1920 CreatedTask = new Task ( name : Name . Text , description : Description . Text ) ;
20- Close ( ) ;
2121 }
2222}
Original file line number Diff line number Diff line change 1+ using System . Windows . Input ;
2+ using CommunityToolkit . Mvvm . Input ;
3+ using Desktop . Common ;
4+
5+ namespace Desktop . Tasks ;
6+
7+ public class TaskCreationViewModel : ViewModelBase
8+ {
9+ public ICommand SaveTask { get ; } =
10+ new RelayCommand < ICloseable > ( closeable => { closeable . Close ( ) ; } ) ;
11+ }
You can’t perform that action at this time.
0 commit comments