Iri*_*son 8 c# command mvvm viewmodel
我正在构建一个使用相当多命令的应用程序,它们使我的viewmodel变得混乱.MVVM对我来说是新手,很抱歉,这个问题有点愚蠢.有没有办法减少混乱?例如,在这里你可以看到杂乱的一部分..
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);
}
Run Code Online (Sandbox Code Playgroud)
所以你有命令:
文件操作(打开,保存,上传到闪烁)
窗口操作(全屏,关闭)
编辑(旋转,调整大小,颜色等)
考虑将相关命令分组(编写)在一个称为FileCommands的自定义类中.如果适用,创建多级层次结构.如果视图中有分层菜单,则可能需要类似的命令层次结构.
然后,为每个命令组(例如FileController)创建一个Controller,并在控制器中创建create方法,该方法将从FileCommands组中注册具有关联服务的命令.
有关如何实际实现Controller/ViewModel映射的一些想法,请参见http://waf.codeplex.com/示例应用程序(例如BookController.cs).但请注意,它不是完全相同的情况(没有将命令分成组).
| 归档时间: |
|
| 查看次数: |
608 次 |
| 最近记录: |