diff --git a/src/Leo.Wpf.App/ViewModels/MainWindowViewModel.cs b/src/Leo.Wpf.App/ViewModels/MainWindowViewModel.cs index 0d060dc..a0c14b3 100644 --- a/src/Leo.Wpf.App/ViewModels/MainWindowViewModel.cs +++ b/src/Leo.Wpf.App/ViewModels/MainWindowViewModel.cs @@ -10,7 +10,6 @@ namespace Leo.Wpf.App.ViewModels { public sealed partial class MainWindowViewModel : ObservableRecipient, IDisposable { - [ObservableProperty] private CustomerViewModel? _currentCustomer; private bool disposedValue; @@ -22,6 +21,21 @@ public sealed partial class MainWindowViewModel : ObservableRecipient, IDisposab private readonly INewCustomerDetailWindowService _newCustomerDetailWindow; private readonly IFindWindowService _findWindow; + public CustomerViewModel? CurrentCustomer + { + get { return _currentCustomer; } + set + { + SetProperty(ref _currentCustomer, value); + NewCustomerDetailCommand.NotifyCanExecuteChanged(); + EditCustomerCommand.NotifyCanExecuteChanged(); + } + } + + public IRelayCommand EditCustomerCommand { get; } + + public IRelayCommand NewCustomerDetailCommand { get; } + public MainWindowViewModel( ICustomerService customerService, ICustomerDetailService detailService, @@ -40,6 +54,12 @@ public MainWindowViewModel( _newCustomerDetailWindow = newCustomerDetailWindowService; _findWindow = findWindowService; + EditCustomerCommand = new RelayCommand(EditCustomer, c => c != null); + NewCustomerDetailCommand = new RelayCommand(NewCustomerDetail, _ => + { + return CurrentCustomer != null; + }); + Messenger.Register(this, (rcpt, msg) => { Task.Run(() => ReloadCurrentCustomerAsync(msg.Id)); @@ -62,19 +82,20 @@ private void NewCustomer() _newCustomerWindow.ShowDialog(); } - [RelayCommand] - private void UpdateCustomer() + private void EditCustomer(CustomerViewModel? customer) { - if (CurrentCustomer != null) + if (customer != null) { - _customerEditorWindow.ShowDialog(CurrentCustomer.Id!); + _customerEditorWindow.ShowDialog(customer.Id!); } } - [RelayCommand] - private void NewCustomerDetail(string customerId) + private void NewCustomerDetail(string? customerId) { - _newCustomerDetailWindow.ShowDialog(customerId); + if (customerId != null) + { + _newCustomerDetailWindow.ShowDialog(customerId); + } } [RelayCommand] diff --git a/src/Leo.Wpf.App/Views/MainWindow.xaml b/src/Leo.Wpf.App/Views/MainWindow.xaml index 2d0b161..103e00d 100644 --- a/src/Leo.Wpf.App/Views/MainWindow.xaml +++ b/src/Leo.Wpf.App/Views/MainWindow.xaml @@ -39,7 +39,8 @@