private void BindFields(CompositeDisposable disposables) { this.OneWayBind(this.ViewModel, vm => vm.Titles, v => v.Titles.ItemsSource) .DisposeWith(disposables); this.OneWayBind(this.ViewModel, vm => vm.OriginalTitles, v => v.OriginalTitles.ItemsSource) .DisposeWith(disposables); var boolToVisibility = new BooleanToVisibilityTypeConverter(); this.WhenAnyValue(v => v.ViewModel.HasTitles) .BindTo(this, v => v.Titles.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.HasTitles) .BindTo(this, v => v.OriginalTitles.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.HasTitles) .BindTo(this, v => v.AddTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.HasTitles) .BindTo(this, v => v.AddOriginalTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.Bind(this.ViewModel, vm => vm.PosterUrl, v => v.PosterUrlTextBox.Text) .DisposeWith(disposables); }
public SeriesComponentControl() { this.InitializeComponent(); this.WhenActivated(disposables => { this.WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this.OneWayBind(this.ViewModel, vm => vm.Title, v => v.TitleTextBlock.Text) .DisposeWith(disposables); this.OneWayBind(this.ViewModel, vm => vm.Years, v => v.YearsTextBlock.Text) .DisposeWith(disposables); this.Events().MouseLeftButtonUp .Discard() .InvokeCommand(this.ViewModel.Select) .DisposeWith(disposables); var boolToVisibility = new BooleanToVisibilityTypeConverter(); this.BindCommand(this.ViewModel, vm => vm.MoveUp, v => v.MoveUpMenuItem) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.MoveUp.CanExecute) .BindTo(this, v => v.MoveUpMenuItem.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.MoveDown, v => v.MoveDownMenuItem) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.MoveDown.CanExecute) .BindTo(this, v => v.MoveDownMenuItem.Visibility, null, boolToVisibility) .DisposeWith(disposables); }); }
private void BindCommands(CompositeDisposable disposables) { var boolToVisibility = new BooleanToVisibilityTypeConverter(); const BooleanToVisibilityHint useHidden = BooleanToVisibilityHint.UseHidden; this.BindCommand(this.ViewModel, vm => vm.GoToSeries, v => v.GoToSeriesButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToSeries, v => v.GoToSeriesIconButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToSeries.CanExecute) .BindTo(this, v => v.GoToSeriesIconButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Cancel, v => v.CancelButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Cancel.CanExecute) .BindTo(this, v => v.CancelButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Close, v => v.CloseButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToNext, v => v.GoToNextButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToNext.CanExecute) .BindTo(this, v => v.GoToNextButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToPrevious, v => v.GoToPreviousButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToPrevious.CanExecute) .BindTo(this, v => v.GoToPreviousButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Close, v => v.CloseButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Delete, v => v.DeleteButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Delete.CanExecute) .BindTo(this, v => v.DeleteButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddTitle, v => v.AddTitleButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddTitle.CanExecute) .BindTo(this, v => v.AddTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddOriginalTitle, v => v.AddOriginalTitleButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddOriginalTitle.CanExecute) .BindTo(this, v => v.AddOriginalTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Save) .Subscribe(_ => this.LoadPoster()) .DisposeWith(disposables); }
public void BindFields(CompositeDisposable disposables) { this.Bind( this.ViewModel, vm => vm.StartMonth, v => v.StartMonthComboBox.SelectedIndex, month => month - 1, index => index + 1) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.IsSingleDayRelease) .Subscribe(isSingleDayRelease => HintAssist.SetHint( this.StartMonthComboBox, isSingleDayRelease ? Messages.Month : Messages.StartMonth)); this.Bind(this.ViewModel, vm => vm.StartYear, v => v.StartYearTextBox.Text) .DisposeWith(disposables); this.StartYearTextBox.ValidateWith(this.ViewModel.StartYearRule) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.IsSingleDayRelease) .Subscribe(isSingleDayRelease => HintAssist.SetHint( this.StartYearTextBox, isSingleDayRelease ? Messages.Year : Messages.StartYear)); var boolToVisibility = new BooleanToVisibilityTypeConverter(); this.Bind( this.ViewModel, vm => vm.EndMonth, v => v.EndMonthComboBox.SelectedIndex, month => month - 1, index => index + 1) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.IsSingleDayRelease) .Invert() .BindTo(this, v => v.EndMonthComboBox.Visibility, null, boolToVisibility); this.Bind(this.ViewModel, vm => vm.EndYear, v => v.EndYearTextBox.Text) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.IsSingleDayRelease) .Invert() .BindTo(this, v => v.EndYearTextBox.Visibility, null, boolToVisibility); this.Bind(this.ViewModel, vm => vm.NumberOfEpisodes, v => v.NumberOfEpisodesTextBox.Text) .DisposeWith(disposables); this.Bind(this.ViewModel, vm => vm.IsSingleDayRelease, v => v.IsSingleDayReleaseCheckBox.IsChecked) .DisposeWith(disposables); this.WhenAnyValue( v => v.ViewModel.StartMonth, v => v.ViewModel.StartYear, v => v.ViewModel.EndMonth, v => v.ViewModel.EndYear) .Select(((int StartMonth, string StartYear, int EndMonth, string EndYear)values) => values.StartMonth == values.EndMonth && values.StartYear == values.EndYear) .BindTo(this, v => v.IsSingleDayReleaseCheckBox.IsEnabled) .DisposeWith(disposables); this.Bind(this.ViewModel, vm => vm.PosterUrl, v => v.PosterUrlTextBox.Text) .DisposeWith(disposables); this.WhenAnyValue(v => v.ViewModel.ShowPosterUrl) .BindTo(this, v => v.PosterUrlTextBox.Visibility, null, boolToVisibility); }
private void BindCommands(CompositeDisposable disposables) { var boolToVisibility = new BooleanToVisibilityTypeConverter(); const BooleanToVisibilityHint useHidden = BooleanToVisibilityHint.UseHidden; this.BindCommand(this.ViewModel, vm => vm.GoToSeries, v => v.GoToSeriesButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToSeries, v => v.GoToSeriesIconButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToSeries.CanExecute) .BindTo(this, v => v.GoToSeriesIconButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Cancel, v => v.CancelButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Cancel.CanExecute) .BindTo(this, v => v.CancelButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Close, v => v.CloseButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToNext, v => v.GoToNextButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToNext.CanExecute) .BindTo(this, v => v.GoToNextButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToPrevious, v => v.GoToPreviousButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToPrevious.CanExecute) .BindTo(this, v => v.GoToPreviousButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Close, v => v.CloseButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Delete, v => v.DeleteButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Delete.CanExecute) .BindTo(this, v => v.DeleteButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.SwitchToNextPoster, v => v.SwitchToNextPosterButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.SwitchToNextPoster.CanExecute) .BindTo(this, v => v.SwitchToNextPosterButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.SwitchToPreviousPoster, v => v.SwitchToPreviousPosterButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.SwitchToPreviousPoster.CanExecute) .BindTo(this, v => v.SwitchToPreviousPosterButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.ViewModel.Periods.ToObservableChangeSet() .Count() .Select(count => count > 1) .ObserveOnDispatcher() .BindTo(this, v => v.SwitchPosterPanel.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddTitle, v => v.AddTitleButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddTitle.CanExecute) .BindTo(this, v => v.AddTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddOriginalTitle, v => v.AddOriginalTitleButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddOriginalTitle.CanExecute) .BindTo(this, v => v.AddOriginalTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddPeriod, v => v.AddPeriodButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddPeriod.CanExecute) .BindTo(this, v => v.AddPeriodButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); }
private void BindCommands(CompositeDisposable disposables) { var boolToVisibility = new BooleanToVisibilityTypeConverter(); const BooleanToVisibilityHint useHidden = BooleanToVisibilityHint.UseHidden; this.BindCommand(this.ViewModel, vm => vm.Save, v => v.SaveButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Cancel, v => v.CancelButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Close, v => v.CloseButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Delete, v => v.DeleteButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToMovieSeries, v => v.GoToMovieSeriesButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToMovieSeries.CanExecute) .BindTo(this, v => v.GoToMovieSeriesButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToMovieSeries, v => v.GoToMovieSeriesArrowButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToMovieSeries.CanExecute) .BindTo(this, v => v.GoToMovieSeriesArrowButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToNext, v => v.GoToNextButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToNext.CanExecute) .BindTo(this, v => v.GoToNextButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.GoToPrevious, v => v.GoToPreviousButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.GoToPrevious.CanExecute) .BindTo(this, v => v.GoToPreviousButton.Visibility, useHidden, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.CreateMovieSeries, v => v.CreateMovieSeriesButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.CreateMovieSeries.CanExecute) .BindTo(this, v => v.CreateMovieSeriesButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Delete.CanExecute) .BindTo(this, v => v.DeleteButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddTitle, v => v.AddTitleButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddTitle.CanExecute) .BindTo(this, v => v.AddTitleButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddOriginalTitle, v => v.AddOriginalTitleButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.AddOriginalTitle.CanExecute) .BindTo(this, v => v.AddOriginalTitleButton.Visibility, null, boolToVisibility); this.BindCommand(this.ViewModel, vm => vm.AddSeason, v => v.AddSeasonButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.AddSpecialEpisode, v => v.AddSpecialEpisodeButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.ConvertToMiniseries, v => v.ConvertToMiniseriesButton) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.ConvertToMiniseries.CanExecute) .BindTo(this, v => v.ConvertToMiniseriesButton.Visibility, null, boolToVisibility) .DisposeWith(disposables); Observable.CombineLatest( this.WhenAnyObservable(v => v.ViewModel.Save.CanExecute), this.WhenAnyObservable(v => v.ViewModel.Cancel.CanExecute)) .AnyTrue() .BindTo(this, v => v.ActionPanel.Visibility, null, boolToVisibility) .DisposeWith(disposables); this.WhenAnyObservable(v => v.ViewModel.Save) .Subscribe(_ => this.LoadPoster()) .DisposeWith(disposables); }