允许编辑
This commit is contained in:
@@ -25,6 +25,18 @@ namespace TodoList.ViewModels
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private TodoPriority newPriority = TodoPriority.Medium;
|
private TodoPriority newPriority = TodoPriority.Medium;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool isEditDialogOpen;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private TodoItem editingTask;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string editContent;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private TodoPriority editPriority = TodoPriority.Medium;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isSettingsOpen;
|
private bool isSettingsOpen;
|
||||||
@@ -189,6 +201,39 @@ namespace TodoList.ViewModels
|
|||||||
Tasks.Remove(item);
|
Tasks.Remove(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void OpenEditDialog(TodoItem item)
|
||||||
|
{
|
||||||
|
if (item == null) return;
|
||||||
|
EditingTask = item;
|
||||||
|
EditContent = item.Content;
|
||||||
|
EditPriority = item.Priority;
|
||||||
|
IsEditDialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void CloseEditDialog()
|
||||||
|
{
|
||||||
|
IsEditDialogOpen = false;
|
||||||
|
EditingTask = null;
|
||||||
|
EditContent = string.Empty;
|
||||||
|
EditPriority = TodoPriority.Medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task SaveEditAsync()
|
||||||
|
{
|
||||||
|
if (EditingTask == null || string.IsNullOrWhiteSpace(EditContent)) return;
|
||||||
|
|
||||||
|
EditingTask.Content = EditContent;
|
||||||
|
EditingTask.Priority = EditPriority;
|
||||||
|
EditingTask.SyncStatus = SyncStatus.Pending;
|
||||||
|
|
||||||
|
await _dataService.SaveTaskAsync(EditingTask);
|
||||||
|
await LoadTasksAsync();
|
||||||
|
CloseEditDialog();
|
||||||
|
}
|
||||||
|
|
||||||
public async void Receive(TaskAddedMessage message)
|
public async void Receive(TaskAddedMessage message)
|
||||||
{
|
{
|
||||||
await LoadTasksAsync();
|
await LoadTasksAsync();
|
||||||
|
|||||||
@@ -172,6 +172,7 @@
|
|||||||
<Setter Property="Background" Value="White"/>
|
<Setter Property="Background" Value="White"/>
|
||||||
<Setter Property="Margin" Value="0,0,0,10"/>
|
<Setter Property="Margin" Value="0,0,0,10"/>
|
||||||
<Setter Property="Padding" Value="10"/>
|
<Setter Property="Padding" Value="10"/>
|
||||||
|
<EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="ListBoxItem">
|
<ControlTemplate TargetType="ListBoxItem">
|
||||||
@@ -232,6 +233,27 @@
|
|||||||
<TextBlock Text="{Binding Priority, Converter={StaticResource EnumDescConverter}}" FontSize="12" Foreground="#888" Margin="0,2,0,0"/>
|
<TextBlock Text="{Binding Priority, Converter={StaticResource EnumDescConverter}}" FontSize="12" Foreground="#888" Margin="0,2,0,0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Column="2" Content="✎"
|
||||||
|
Command="{Binding DataContext.OpenEditDialogCommand, RelativeSource={RelativeSource AncestorType=Window}}"
|
||||||
|
CommandParameter="{Binding}"
|
||||||
|
Width="24" Height="24"
|
||||||
|
Background="Transparent" Foreground="#007AFF"
|
||||||
|
BorderThickness="0" FontSize="12" FontWeight="Bold"
|
||||||
|
Cursor="Hand" Margin="0,0,5,0">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border x:Name="border" Background="{TemplateBinding Background}" CornerRadius="12">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
<ControlTemplate.Triggers>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Setter TargetName="border" Property="Background" Value="#1A007AFF"/>
|
||||||
|
</Trigger>
|
||||||
|
</ControlTemplate.Triggers>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button Grid.Column="3" Content="✕"
|
<Button Grid.Column="3" Content="✕"
|
||||||
Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=Window}}"
|
Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=Window}}"
|
||||||
CommandParameter="{Binding}"
|
CommandParameter="{Binding}"
|
||||||
@@ -301,5 +323,52 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Edit Dialog Overlay -->
|
||||||
|
<Grid Grid.RowSpan="3" Background="#80000000" Visibility="{Binding IsEditDialogOpen, Converter={StaticResource BoolToVis}}">
|
||||||
|
<Border Background="White" Width="350" Height="250" CornerRadius="10" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="20">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<TextBlock Text="编辑任务" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,0,0,15"/>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="1" VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="任务内容" Foreground="#666" Margin="0,0,0,5" FontSize="12"/>
|
||||||
|
<TextBox Text="{Binding EditContent, UpdateSourceTrigger=PropertyChanged}"
|
||||||
|
FontSize="14" Padding="8" Margin="0,0,0,15" BorderThickness="1" BorderBrush="#DDD"
|
||||||
|
VerticalContentAlignment="Center"/>
|
||||||
|
|
||||||
|
<TextBlock Text="优先级" Foreground="#666" Margin="0,0,0,5" FontSize="12"/>
|
||||||
|
<ComboBox ItemsSource="{Binding Source={StaticResource PriorityEnum}}"
|
||||||
|
SelectedItem="{Binding EditPriority}"
|
||||||
|
Width="300" VerticalContentAlignment="Center" BorderThickness="1" BorderBrush="#DDD">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Converter={StaticResource EnumDescConverter}}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,15,0,0">
|
||||||
|
<Button Content="取消" Command="{Binding CloseEditDialogCommand}" Width="80" Margin="0,0,10,0"
|
||||||
|
Background="#EEE" Foreground="#333" Height="30" BorderThickness="0">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="5">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
</Button>
|
||||||
|
<Button Content="保存" Command="{Binding SaveEditCommand}" Width="80" Height="30" Style="{StaticResource ModernButton}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using TodoList.ViewModels;
|
using TodoList.ViewModels;
|
||||||
|
|
||||||
@@ -77,5 +78,13 @@ namespace TodoList.Views
|
|||||||
vm.ShortcutKey = keyStr;
|
vm.ShortcutKey = keyStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is ListBoxItem item && item.DataContext is Models.TodoItem todoItem && DataContext is MainViewModel vm)
|
||||||
|
{
|
||||||
|
vm.OpenEditDialogCommand.Execute(todoItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user