Skip to content

Commit bac9e84

Browse files
committed
revert: "feactor: convert editing event handler to Command in ViewModel + change it from double click to simply an edit button".
I've realized that the Edit event handler only has view related code, so the responsibilities are well distributed.
1 parent e8a832b commit bac9e84

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

Desktop/Project/TaskListViewModel.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ public TaskListViewModel(
3131
Tasks.Add(taskCreationViewModel.CreatedTask);
3232
});
3333

34-
Edit = new RelayCommand<Task>(taskToEdit =>
35-
{
36-
var window = new TaskEditing(taskToEdit!);
37-
window.ShowDialog();
38-
});
39-
4034
Delete = new RelayCommand<Task>(taskToRemove =>
4135
{
4236
Tasks.Remove(taskToRemove!);
@@ -46,7 +40,6 @@ public TaskListViewModel(
4640

4741
public ICommand Add { get; }
4842

49-
public ICommand Edit { get; }
5043
public ICommand Delete { get; }
5144

5245
public void PopulateTasks()

Desktop/Project/TasksList.xaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
mc:Ignorable="d"
88
xmlns:domain="clr-namespace:Desktop.Domain">
9+
<UserControl.Resources>
10+
<Style TargetType="ListBoxItem">
11+
<EventSetter Event="MouseDoubleClick" Handler="Edit" />
12+
</Style>
13+
</UserControl.Resources>
914
<Grid>
1015
<StackPanel>
1116
<StackPanel Orientation="Horizontal">
@@ -18,9 +23,6 @@
1823
<DataTemplate DataType="{x:Type domain:Task}">
1924
<StackPanel Orientation="Horizontal">
2025
<TextBlock Text="{Binding Name}" />
21-
<Button Content="Edit"
22-
Command="{Binding DataContext.Edit, ElementName=Root}"
23-
CommandParameter="{Binding}" />
2426
<Button Content="Delete"
2527
Command="{Binding DataContext.Delete, ElementName=Root}"
2628
CommandParameter="{Binding}" />

Desktop/Project/TasksList.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Windows.Controls;
2+
using System.Windows.Input;
23
using Desktop.Tasks;
4+
using Task = Desktop.Domain.Task;
35

46
namespace Desktop.Project;
57

@@ -16,4 +18,13 @@ public TasksList(TaskListViewModel viewModel)
1618
viewModel.TaskCreationViewCreator = creationViewModel =>
1719
new TaskCreation(creationViewModel);
1820
}
21+
22+
private void Edit(object sender, MouseButtonEventArgs e)
23+
{
24+
if (sender is not ListBoxItem { DataContext: Task task })
25+
return;
26+
27+
var window = new TaskEditing(task);
28+
window.ShowDialog();
29+
}
1930
}

Desktop/Tasks/TaskEditing.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Windows;
2-
using Desktop.Common;
32
using Task = Desktop.Domain.Task;
43

54
namespace Desktop.Tasks;

0 commit comments

Comments
 (0)