修正BUG
This commit is contained in:
parent
84851bbb0d
commit
524e9c5c9b
@ -20,10 +20,15 @@ public partial class VarietyViewModel : ObservableObject
|
|||||||
|
|
||||||
private readonly IVarietyService _varietyService;
|
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);
|
Pallets = new ObservableCollection<Pallet>(palletManagerViewModel.Pallets);
|
||||||
|
|
||||||
|
_homeViewModel = homeViewModel;
|
||||||
|
|
||||||
_varietyService = varietyService;
|
_varietyService = varietyService;
|
||||||
|
|
||||||
_varieties = new ObservableCollection<Variety>(varietyService.GetAll());
|
_varieties = new ObservableCollection<Variety>(varietyService.GetAll());
|
||||||
@ -35,12 +40,12 @@ public partial class VarietyViewModel : ObservableObject
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SavePalletCompletedMessage
|
public class SaveVarietyCompletedMessage
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void OnDeletePallet(object obj)
|
private void OnDeleteVariety(object obj)
|
||||||
{
|
{
|
||||||
if (obj is Variety variety)
|
if (obj is Variety variety)
|
||||||
{
|
{
|
||||||
@ -54,7 +59,7 @@ public partial class VarietyViewModel : ObservableObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void OnSavePallet(object obj)
|
private void OnSaveVariety(object obj)
|
||||||
{
|
{
|
||||||
if (obj is Variety variety)
|
if (obj is Variety variety)
|
||||||
{
|
{
|
||||||
@ -66,6 +71,8 @@ public partial class VarietyViewModel : ObservableObject
|
|||||||
_varietyService.UpdateVarietyAsync(variety);
|
_varietyService.UpdateVarietyAsync(variety);
|
||||||
}
|
}
|
||||||
|
|
||||||
WeakReferenceMessenger.Default.Send(new PalletManagerViewModel.SavePalletCompletedMessage());
|
//同步更新主页的品种列表
|
||||||
|
_homeViewModel.Varieties = Varieties;
|
||||||
|
WeakReferenceMessenger.Default.Send(new SaveVarietyCompletedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -329,13 +329,13 @@
|
|||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Button Margin="0,0,10,0" Content="保存"
|
<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}"
|
CommandParameter="{Binding}"
|
||||||
Visibility="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
Visibility="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||||
<!-- 删除按钮 -->
|
<!-- 删除按钮 -->
|
||||||
<Button Content="删除"
|
<Button Content="删除"
|
||||||
Background="Red"
|
Background="Red"
|
||||||
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.DeletePalletCommand}"
|
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.DeleteVarietyCommand}"
|
||||||
CommandParameter="{Binding}" />
|
CommandParameter="{Binding}" />
|
||||||
<!-- 保存按钮,根据 DataGridRow 的 IsEditing 属性控制可见性 -->
|
<!-- 保存按钮,根据 DataGridRow 的 IsEditing 属性控制可见性 -->
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public partial class VarietyPage : Page
|
|||||||
ViewModel = viewModel;
|
ViewModel = viewModel;
|
||||||
DataContext = this;
|
DataContext = this;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
WeakReferenceMessenger.Default.Register<PalletManagerViewModel.SavePalletCompletedMessage>(this, (r, m) =>
|
WeakReferenceMessenger.Default.Register<VarietyViewModel.SaveVarietyCompletedMessage>(this, (r, m) =>
|
||||||
{
|
{
|
||||||
// 提交当前编辑并取消编辑模式
|
// 提交当前编辑并取消编辑模式
|
||||||
VarietyDataGrid.CommitEdit();
|
VarietyDataGrid.CommitEdit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user