public MainWindow() { InitializeComponent(); var converterService = new ImageConverterService(); DataContext = new MainWindowViewModel(converterService); }
/// <summary> /// Initializes a new instance of the <see cref="MainForm" /> class. /// </summary> /// <param name="applicationSettingsService">The application settings service.</param> /// <param name="userConfigService">The user configuration service.</param> /// <param name="converterService"></param> public MainForm(ApplicationSettingsService applicationSettingsService, UserConfigService userConfigService, ImageConverterService converterService) { _applicationSettingsService = applicationSettingsService; _userConfigService = userConfigService; _converterService = converterService; InitializeComponent(); }
public MainWindowViewModel(ImageConverterService converterService) { this.converterService = converterService; Images = new ReactiveList <OwnImage>(); // when something changes in the draggedFolders collection // keep an eye on ShouldReset var addedOrRemoved = Observable.Merge( DraggedFolders.ItemsAdded, DraggedFolders.ItemsRemoved ); DraggedFolders.ItemsAdded .SelectMany(x => LoadImagesFromFolder(x)) .Subscribe(x => Images.AddRange(x)); imagesCount = Images.CountChanged.ToProperty(this, x => x.ImagesCount); var canExecuteCompress = this.WhenAnyValue(x => x.ImagesCount) .Select(x => x > 0); //commands Compress = ReactiveCommand.CreateAsyncObservable( canExecuteCompress, _ => ConvertImages().TakeUntil(CancelConversion) ); isBusy = Compress.IsExecuting.ToProperty(this, x => x.IsBusy); Compress.ObserveOn(RxApp.MainThreadScheduler).Subscribe(x => Images.Remove(x)); Compress.ThrownExceptions .Select(ex => new UserError(ex.Message, ex.Source)) .Subscribe(ex => Debug.WriteLine(ex.ErrorMessage)); var canExecuteCancelConversion = this.WhenAnyValue(x => x.ImagesCount, x => x.IsBusy, (count, busy) => count > 0 && busy) .Select(x => x); CancelConversion = ReactiveCommand.CreateAsyncObservable(canExecuteCancelConversion, _ => { return(Observable.Return <Unit>(Unit.Default)); }); CancelConversion.ThrownExceptions .Select(ex => new UserError(ex.Message, ex.Source)) .Subscribe(ex => Debug.WriteLine(ex.ErrorMessage)); }