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 IShowable
4+ {
5+ bool ? ShowDialog ( ) ;
6+ }
Original file line number Diff line number Diff line change @@ -13,13 +13,19 @@ public class TaskListViewModel : ViewModelBase
1313 private readonly ITaskRepository taskRepository ;
1414 public ObservableCollection < Task > Tasks { get ; } = [ ] ;
1515
16- public TaskListViewModel ( ITaskRepository taskRepository )
16+ public Func < TaskCreationViewModel , IShowable > TaskCreationViewCreator { get ; set ; }
17+
18+ public TaskListViewModel (
19+ ITaskRepository taskRepository ,
20+ TaskCreationViewModel taskCreationViewModel )
1721 {
1822 this . taskRepository = taskRepository ;
1923
20- Add = new RelayCommand < TaskCreationViewModel > ( taskCreationViewModel =>
24+ Add = new RelayCommand ( ( ) =>
2125 {
22- if ( taskCreationViewModel ! . CreatedTask is null )
26+ TaskCreationViewCreator ! ( taskCreationViewModel ) . ShowDialog ( ) ;
27+
28+ if ( taskCreationViewModel . CreatedTask is null )
2329 return ;
2430
2531 Tasks . Add ( taskCreationViewModel . CreatedTask ) ;
Original file line number Diff line number Diff line change 1414 <StackPanel >
1515 <StackPanel Orientation =" Horizontal" >
1616 <Label Content =" Tasks:" />
17- <Button AutomationProperties.AutomationId=" AddTask" Content =" _Add task" Click = " Add" />
17+ <Button AutomationProperties.AutomationId=" AddTask" Content =" _Add task" Command = " {Binding Add} " />
1818 </StackPanel >
1919
2020 <ListBox Name =" Tasks" >
Original file line number Diff line number Diff line change @@ -19,19 +19,15 @@ public TasksList(
1919 {
2020 this . taskRepository = taskRepository ;
2121 this . viewModel = viewModel ;
22+ DataContext = viewModel ;
2223 this . taskCreationViewModel = taskCreationViewModel ;
2324
2425 InitializeComponent ( ) ;
2526 Tasks . ItemsSource = viewModel . Tasks ;
2627
2728 viewModel . PopulateTasks ( ) ;
28- }
29-
30- private void Add ( object sender , RoutedEventArgs e )
31- {
32- new TaskCreation ( taskCreationViewModel ) . ShowDialog ( ) ;
33-
34- viewModel . Add . Execute ( taskCreationViewModel ) ;
29+ viewModel . TaskCreationViewCreator = creationViewModel =>
30+ new TaskCreation ( creationViewModel ) ;
3531 }
3632
3733 private void Edit ( object sender , MouseButtonEventArgs e )
Original file line number Diff line number Diff line change 11using System . Windows ;
22using Desktop . Common ;
3- using Task = Desktop . Domain . Task ;
43
54namespace Desktop . Tasks ;
65
7- using Task = Task ;
8-
9- public partial class TaskCreation : Window , ICloseable
6+ public partial class TaskCreation : Window , ICloseable , IShowable
107{
11- private readonly TaskCreationViewModel viewModel ;
12-
138 public TaskCreation ( TaskCreationViewModel viewModel )
149 {
1510 InitializeComponent ( ) ;
1611 DataContext = viewModel ;
17- this . viewModel = viewModel ;
1812 }
19-
20- public Task ? CreatedTask => viewModel . CreatedTask ;
2113}
You can’t perform that action at this time.
0 commit comments