我正在構建一個使用相當多的命令的應用程序,並且它們混亂了我的視圖模型。 MVVM對我來說是新手,所以如果這個問題有點愚蠢,那麼很抱歉。有沒有辦法減少混亂?例如在這裏你可以看到雜亂的一部分..如何避免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);
}
我也有興趣看到一個很好的答案,但AFAIK這是所有的鬆耦合善良支付的代價。 – Jon 2011-12-18 15:08:48