public ImagesView() { InitializeComponent(); this.WhenActivated(disposableRegistration => { this.OneWayBind(ViewModel, vm => vm.SelectedImage, view => view.SelectedImage.Source, PathToImage) .DisposeWith(disposableRegistration); this.OneWayBind(ViewModel, vm => vm.Images, view => view.Images.ItemsSource) .DisposeWith(disposableRegistration); this.Bind(ViewModel, vm => vm.SelectedIndex, view => view.Images.SelectedIndex) .DisposeWith(disposableRegistration); this.Bind(ViewModel, vm => vm.SearchTerm, view => view.SearchTerm.Text) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.GoLeft, view => view.GoLeft) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.GoRight, view => view.GoRight) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.RenameImage, view => view.Rename) .DisposeWith(disposableRegistration); ViewModel.PromptForNewFileName.RegisterHandler(ic => { var inputBox = new InputBox(Text.RenameImagePromptText, Text.RenameImagePromptTitle); if (inputBox.ShowDialog() == true) { ic.SetOutput(inputBox.Answer); } else { ic.SetOutput(null); } }); ViewModel.NotifyUserOfError.RegisterHandler(ic => { var messageBox = new MessageBoxModel { Caption = Text.Error, Text = ic.Input, Buttons = new[] { MessageBoxButtons.Ok(Text.OK) }, Icon = MessageBoxImage.Error }; MessageBox.Show(messageBox); ic.SetOutput(Unit.Default); }); ViewModel.GoLeft .Merge(ViewModel.GoRight) .Subscribe(_ => { if (Images.ItemContainerGenerator.ContainerFromItem(Images.SelectedItem) is ListBoxItem item) { item.Focus(); } }) .DisposeWith(disposableRegistration); }); }
public FoldersView() { InitializeComponent(); this.WhenActivated(disposableRegistration => { ViewModel.SelectFolder.RegisterHandler(ic => { var folderBrowser = new FolderBrowserDialog { ShowNewFolderButton = true }; if (folderBrowser.ShowDialog() == DialogResult.OK) { ic.SetOutput(folderBrowser.SelectedPath); } }).DisposeWith(disposableRegistration); ViewModel.PromptForName.RegisterHandler(ic => { var inputBox = new InputBox(Text.NewFolderPromptText, Text.NewFolderPromptTitle); if (inputBox.ShowDialog() == true) { ic.SetOutput(inputBox.Answer); } else { ic.SetOutput(null); } }).DisposeWith(disposableRegistration); var currentFolder = new ObservableCollection <FolderTreeItemViewModel>(); ViewModel.WhenAnyValue(x => x.CurrentFolder) .Where(c => c != null) .Subscribe(f => { currentFolder.Clear(); currentFolder.Add(f); }) .DisposeWith(disposableRegistration); var compositeCollection = new CompositeCollection { new CollectionContainer { Collection = currentFolder }, new CollectionContainer { Collection = ViewModel.PinnedFolders } }; Folders.ItemsSource = compositeCollection; this.Bind(ViewModel, vm => vm.Selected, view => view.Folders.SelectedItem) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.Pin, view => view.Pin) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.PinSelected, view => view.PinSelected) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.UnpinSelected, view => view.Unpin) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.CreateFolderUnderSelected, view => view.CreateFolder) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.MoveSelectedPinnedFolderUp, view => view.MoveSelectedPinnedFolderUp) .DisposeWith(disposableRegistration); this.BindCommand(ViewModel, vm => vm.MoveSelectedPinnedFolderDown, view => view.MoveSelectedPinnedFolderDown) .DisposeWith(disposableRegistration); ViewModel.WhenAnyValue(x => x.CurrentFolder) .Where(c => c != null) .Select(_ => Unit.Default) .Subscribe(_ => SelectCurrentFolder()) .DisposeWith(disposableRegistration); var settings = Locator.Current.GetService <SettingsViewModel>(); var pinnedFolderSettings = settings.GetGroup <PinnedFolderSettingsViewModel>(); // restore pinned folders ViewModel.AddPinnedFoldersFromPaths(pinnedFolderSettings.PinnedFolders); // save pinned folders ViewModel.PinnedFolders.ActOnEveryObject(f => { if (f == null) { return; } pinnedFolderSettings.PinnedFolders = ViewModel.PinnedFolders.Select(p => p.Path); }, f => { if (f == null) { return; } pinnedFolderSettings.PinnedFolders = ViewModel.PinnedFolders.Select(p => p.Path); }); }); }