private void UpdateNodeCache(Action <ISourceUpdater <ItemViewModelBase, string> > updateAction) { int selectedItemIndex = SelectedItemIndex; NodeItemViewModelCache.Edit(updateAction); SelectedItemIndex = selectedItemIndex; }
private ShellViewModel() { FilePath = new BehaviorSubject <string>(@"Test.mrpd"); this.WhenActivated(d => { TestCommand = ReactiveCommand.Create(() => { TestName = "Test"; }); (LoadFileCommand = ReactiveCommand.Create(LoadFile)).DisposeWith(d); (UpCommand = ReactiveCommand.Create(Up, this.WhenAnyValue(s => s.SelectedNodeIndex).Select(i => i > 0))).DisposeWith(d); (CreateNodeCommand = ReactiveCommand.Create(CreateNode)).DisposeWith(d); (_deleteNodeCommand = ReactiveCommand.Create <string>(DeleteNode)).DisposeWith(d); (_enterNodeCommand = ReactiveCommand.Create <string>(EnterNode)).DisposeWith(d); (_startRenameNodeCommand = ReactiveCommand.Create <string>(StartRenameNode)).DisposeWith(d); (_endRenameNodeCommand = ReactiveCommand.Create <(string, string)>(EndRenameNode)).DisposeWith(d); (_deleteDataCommand = ReactiveCommand.Create <string>(DeleteData)).DisposeWith(d); NodeNameList.Connect().ObserveOnDispatcher(DispatcherPriority.Background).Bind(out _nodeNames).Subscribe().DisposeWith(d); NodeItemViewModelCache.Connect().Sort(SortExpressionComparer <ItemViewModelBase> .Ascending(i => i.Name)).Concat(DataItemViewModelCache.Connect().Sort(SortExpressionComparer <ItemViewModelBase> .Ascending(i => i.Name))).Bind(out _itemViewModels).Subscribe().DisposeWith(d); this.WhenAnyValue(s => s.SelectedNodeIndex).Skip(1).Subscribe(SelectedNodeIndexChanged).DisposeWith(d); FilePath.Subscribe(FilePathChanged).DisposeWith(d); FilePath.Select(f => f != null).ToProperty(this, s => s.HasFile, out _hasFile).DisposeWith(d); (SaveCommand = ReactiveCommand.Create(async() => { await this.ShowProgressAsync("", "正在保存..."); })).DisposeWith(d); }); }
private async void DeleteNode(string name) { await Connection.DeleteNodeAsync(name); NodeItemViewModelCache.RemoveKey(name); }