제목을 어떻게 지어야 할지 모르겠네요. 제가 MVVM은 잘 몰라서 말이죠 ㅠㅠ
이번에 아발로니아로 뭐 하나 만들어보고 있는데 (참고로 아발로니아는 이번이 처음이고 ReactiveUI 말고 CommunityToolkit 선택했습니다.) 한 뷰모델의 속성이 변경되면 다른 뷰모델에 있는 커맨드를 (비)활성화 시키려고 합니다. 대충 코드는 이렇습니다.
public sealed partial class InstallWimPageViewModel : PageViewModelBase {
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanNavigateNext))]
private string installWimPath = string.Empty;
public override string Title => "Select install.wim path";
public override string Description => "Select the path to the install.wim file.";
public override bool CanNavigateNext => !string.IsNullOrWhiteSpace(InstallWimPath) && File.Exists(InstallWimPath);
public override bool CanNavigatePrevious => false;
}
public sealed partial class MainWindowViewModel : ViewModelBase {
private readonly PageViewModelBase[] pages = [new InstallWimPageViewModel()];
private PageViewModelBase currentPage;
public MainWindowViewModel() => currentPage = pages[0];
public PageViewModelBase CurrentPage {
get => currentPage;
private set => SetProperty(ref currentPage, value);
}
private bool CanNavigateNext => CurrentPage.CanNavigateNext;
private bool CanNavigatePrevious => CurrentPage.CanNavigatePrevious;
[RelayCommand(CanExecute = nameof(CanNavigateNext))]
private void NavigateNext() => CurrentPage = pages[Array.IndexOf(pages, CurrentPage) + 1];
[RelayCommand(CanExecute = nameof(CanNavigatePrevious))]
private void NavigatePrevious() => CurrentPage = pages[Array.IndexOf(pages, CurrentPage) - 1];
}
InstallWimPageViewModel의 CanNavigateNext 속성이 변경되면 MainWindowViewModel의 NavigateNext(Command)를 (비)활성화 시키고 싶은데 installWimPath에 NotifyCanExecuteChangedFor를 붙어려고 보니까 커맨드가 같은 클래스에 있어야 한다고 합니다. 이걸 어쩌면 좋을까요?