修正BUG

This commit is contained in:
anerx 2025-03-18 20:42:05 +08:00
parent 84851bbb0d
commit 524e9c5c9b
3 changed files with 15 additions and 8 deletions

View File

@ -20,10 +20,15 @@ public partial class VarietyViewModel : ObservableObject
private readonly IVarietyService _varietyService;
public VarietyViewModel(PalletManagerViewModel palletManagerViewModel, IVarietyService varietyService)
private readonly HomeViewModel _homeViewModel;
public VarietyViewModel(PalletManagerViewModel palletManagerViewModel, IVarietyService varietyService,
HomeViewModel homeViewModel)
{
Pallets = new ObservableCollection<Pallet>(palletManagerViewModel.Pallets);
_homeViewModel = homeViewModel;
_varietyService = varietyService;
_varieties = new ObservableCollection<Variety>(varietyService.GetAll());
@ -35,12 +40,12 @@ public partial class VarietyViewModel : ObservableObject
});
}
public class SavePalletCompletedMessage
public class SaveVarietyCompletedMessage
{
}
[RelayCommand]
private void OnDeletePallet(object obj)
private void OnDeleteVariety(object obj)
{
if (obj is Variety variety)
{
@ -54,7 +59,7 @@ public partial class VarietyViewModel : ObservableObject
}
[RelayCommand]
private void OnSavePallet(object obj)
private void OnSaveVariety(object obj)
{
if (obj is Variety variety)
{
@ -66,6 +71,8 @@ public partial class VarietyViewModel : ObservableObject
_varietyService.UpdateVarietyAsync(variety);
}
WeakReferenceMessenger.Default.Send(new PalletManagerViewModel.SavePalletCompletedMessage());
//同步更新主页的品种列表
_homeViewModel.Varieties = Varieties;
WeakReferenceMessenger.Default.Send(new SaveVarietyCompletedMessage());
}
}

View File

@ -329,13 +329,13 @@
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Margin="0,0,10,0" Content="保存"
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.SavePalletCommand}"
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.SaveVarietyCommand}"
CommandParameter="{Binding}"
Visibility="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing, Converter={StaticResource BooleanToVisibilityConverter}}" />
<!-- 删除按钮 -->
<Button Content="删除"
Background="Red"
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.DeletePalletCommand}"
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.DeleteVarietyCommand}"
CommandParameter="{Binding}" />
<!-- 保存按钮,根据 DataGridRow 的 IsEditing 属性控制可见性 -->

View File

@ -20,7 +20,7 @@ public partial class VarietyPage : Page
ViewModel = viewModel;
DataContext = this;
InitializeComponent();
WeakReferenceMessenger.Default.Register<PalletManagerViewModel.SavePalletCompletedMessage>(this, (r, m) =>
WeakReferenceMessenger.Default.Register<VarietyViewModel.SaveVarietyCompletedMessage>(this, (r, m) =>
{
// 提交当前编辑并取消编辑模式
VarietyDataGrid.CommitEdit();