public ScreenshotViewModel(IScreenshotView view, IScreenshotService screenshotService)
        {
            _screenshotService = screenshotService;
            View             = view;
            View.DataContext = this;

            StartCommand = new DelegateCommand(() =>
            {
                var config = GetConfig();
                if (config != null)
                {
                    _screenshotService.Start(config.IP, config.User, config.Pass);
                    Running = true;
                }
            }, () => !Running);

            StopCommand = new DelegateCommand(() =>
            {
                _screenshotService.Stop();
                Running = false;
            }, () => Running);

            _screenshotService.OnImageArrived += img =>
            {
                ((UserControl)this.View).Dispatcher.BeginInvoke(new Action(() =>
                {
                    Image = CreateBitmapSourceFromGdiBitmap(img as Bitmap);
                }));
            };
        }
        public ScreenshotPresenter(IScreenshotView screenshotView, ScreenshotModel screenshotModel)
        {
            ScreenshotView  = screenshotView;
            ScreenshotModel = screenshotModel;

            ScreenshotView.CopyScreenshotToClipboard += ScreenshotView_CopyScreenshotToClipboard;
            ScreenshotView.SaveScreenshotToFile      += ScreenshotView_SaveScreenshotToFile;
        }
示例#3
0
        public ScreenshotViewModel(IScreenshotView view, IEventAggregator eventAggregator)
        {
            View             = view;
            View.DataContext = this;

            eventAggregator.GetEvent <ScreenshotEvent>().Subscribe(img =>
            {
                Image = CreateBitmapSourceFromGdiBitmap(img as Bitmap);
            }, ThreadOption.UIThread);

            StartCommand = new DelegateCommand(() => eventAggregator.GetEvent <ScreenshotStartEvent>().Publish(null), () => !Running);
            StopCommand  = new DelegateCommand(() => eventAggregator.GetEvent <ScreenshotStopEvent>().Publish(null), () => Running);

            eventAggregator.GetEvent <ScreenshotRunningEvent>().Subscribe(state => Running = state, ThreadOption.UIThread);
        }