Tôi đang xây dựng một ứng dụng sử dụng khá nhiều lệnh và chúng đang làm lộn xộn lên chế độ xem của tôi. MVVM là mới đối với tôi, vì vậy xin lỗi nếu câu hỏi này là một chút ngu ngốc. Có cách nào để giảm sự lộn xộn không? Ví dụ ở đây bạn sẽ nhìn thấy một phần của sự lộn xộn ..Làm cách nào để tránh lệnh lộn xộn trong ViewModel?
private void InitializeCommands()
{
LogoutCommand = new RelayCommand(Logout);
OpenCommand = new RelayCommand(SetImage);
SaveCommand = new RelayCommand(SaveImage, SaveImageCanExecute);
UploadToFlickrCommand = new RelayCommand(UploadToFlickr);
CropCommand = new RelayCommand(SetCropMouseEvents);
RemoveRedEyeCommand = new RelayCommand(SetRemoveRedEyeMouseEvents);
TextInputCropCommand = new RelayCommand(CropFromText);
ReloadImageCommand = new RelayCommand(ReloadImage);
FlipYCommand = new RelayCommand(FlipY);
Rotate90RCommand = new RelayCommand(Rotate90R);
FlipXCommand = new RelayCommand(FlipX);
ToGrayscaleCommand = new RelayCommand(ToGrayscale);
ToSepiaCommand = new RelayCommand(ToSepia);
WindowClosingCommand = new RelayCommand(WindowClosing);
EffectsViewCommand = new RelayCommand(() => CurrentToolView = new EffectsView());
AddTextCommand = new RelayCommand(() => CurrentToolView = new AddTextView());
ResizeCommand = new RelayCommand(() => CurrentToolView = new ResizeView());
CropViewCommand = new RelayCommand(() => CurrentToolView = new CropView());
RedEyeCommand = new RelayCommand(() => CurrentToolView = new RedEyeView());
RotateViewCommand = new RelayCommand(() => CurrentToolView = new RotateView());
ExitCommand = new RelayCommand(() => Application.Current.Shutdown());
FullscreenCommand = new RelayCommand(() =>
{
var fs = new FullscreenView
{FullscreenImage = CurrentImage.LoadedImage};
fs.Show();
});
HandleDropCommand = new RelayCommand<DragEventArgs>(e => OnFileDrop(this, e));
Messenger.Default.Register<User>(this, "UserLogin", SetUser);
Messenger.Default.Register<FlickrAccount>(this, "AddedAccount", AddAccount);
Messenger.Default.Register<string>(this, "INeedAUser", SendUser);
Messenger.Default.Register<string>(this, "INeedAImage", SendImage);
}
Tôi cũng muốn được xem câu trả lời hay cho điều này, nhưng AFAIK đây là mức giá phải trả cho việc có tất cả sự tốt đẹp khớp nối lỏng lẻo. – Jon