かなりの数のコマンドを使用するアプリケーションを構築しています。それらは私のviewmodelを乱雑にしています。 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