public MainWindow() { this.InitializeComponent(); this.WhenActivated(disposables => { this.WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this.InitializeMainTabControl(disposables); this.InitializeMenu(disposables); this.ViewModel !.OpenFile .WhereNotNull() .Where(model => model.IsExternal) .Discard() .ObserveOnDispatcher() .Subscribe(this.OnOpenFileExternally) .DisposeWith(disposables); this.Events().Drop .Where(e => e.Data.GetDataPresent(DataFormats.FileDrop)) .SelectMany(e => (string[])e.Data.GetData(DataFormats.FileDrop)) .Select(file => new OpenFileModel(file) { IsExternal = true }) .InvokeCommand(this.ViewModel.OpenFile) .DisposeWith(disposables); this.Events().Closing .Do(e => e.Cancel = true) .Discard() .InvokeCommand(this.ViewModel.Shutdown) .DisposeWith(disposables); this.ViewModel.Shutdown .Subscribe(() => { disposables.Dispose(); this.Close(); }) .DisposeWith(disposables); }); }
public MainWindow() { this.InitializeComponent(); this.WhenActivated(disposables => { this.WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this.InitializeMainTabControl(disposables); this.InitializeMenu(disposables); this.ViewModel !.OpenFile .WhereNotNull() .Where(model => model.IsExternal) .Discard() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(this.OnOpenFileExternally) .DisposeWith(disposables); this.GetObservable(DragDrop.DropEvent) .Where(e => e.Data.Contains(DataFormats.FileNames)) .SelectMany(e => e.Data.GetFileNames() ?? Enumerable.Empty <string>()) .Select(file => new OpenFileModel(file) { IsExternal = true }) .InvokeCommand(this.ViewModel.OpenFile) .DisposeWith(disposables); Observable.FromEventPattern <CancelEventArgs>(h => this.Closing += h, h => this.Closing -= h) .Do(e => e.EventArgs.Cancel = true) .Discard() .InvokeCommand(this.ViewModel.Shutdown) .DisposeWith(disposables); this.ViewModel.Shutdown .Subscribe(() => { disposables.Dispose(); this.Close(); }) .DisposeWith(disposables); }); }