コード例 #1
0
 public AccentColorMenuData()
 {
     ChangeAccentCommand = ReactiveUI.ReactiveCommand.Create();
     ChangeAccentCommand.Subscribe(x => DoChangeTheme(x));
 }
コード例 #2
0
        public MainWindowViewModel()
        {
            Items = new ReactiveList <TodoItem> {
                ChangeTrackingEnabled = true
            };
            Items.ItemsAdded.Subscribe(i => i.DeleteCommand.Subscribe(_ => Items.Remove(i)));

            var itemDoneChanged = Items.ItemChanged.Where(x => x.PropertyName == "Done").Select(_ => Unit.Default);
            var countChanged    = Items.CountChanged.Select(_ => Unit.Default);

            itemDoneChanged.Merge(countChanged).Subscribe(x1 => ItemsLeftCount = Items.Count(i => !i.Done));

            FilteredItems = Items.CreateDerivedCollection(x => x, (Func <TodoItem, bool>)FilterItem);

            var canCreate = this.ObservableForProperty(vm => vm.NewItemText).Select(s => !String.IsNullOrWhiteSpace(s.Value));

            CreateCommand = ReactiveCommand.Create(canCreate);
            CreateCommand.SelectArgs <KeyEventArgs>()
            .Where(x => x.Key == Key.Enter)
            .Subscribe(CreateItemExecute);
            //Items.Add(new TodoItem("ASDASD"));

            ChangeThemeCommand = ReactiveCommand.Create();
            ChangeThemeCommand.Subscribe(_ =>
            {
                ThemeManager.ChangeAppStyle(Application.Current,
                                            ThemeManager.DetectAppStyle(Application.Current).Item2,
                                            ThemeManager.AppThemes.ElementAt(_ThemeIndex++ % ThemeManager.AppThemes.Count()));
            });
            ChangeAccentCommand = ReactiveCommand.Create();
            ChangeAccentCommand.Subscribe(_ =>
            {
                ThemeManager.ChangeAppStyle(Application.Current,
                                            ThemeManager.Accents.ElementAt(_ThemeAccent++ % ThemeManager.Accents.Count()),
                                            ThemeManager.DetectAppStyle(Application.Current).Item1);
            });

            LoadCommand = ReactiveCommand.CreateAsyncObservable(_ => Observable.Create <TodoItem>(obs =>
            {
                if (!failedYet)
                {
                    obs.OnError(new Exception("test"));
                    failedYet = true;
                }
                else
                {
                    failedYet = false;
                    obs.OnNext(new TodoItem("a"));
                    obs.OnNext(new TodoItem("b"));
                    obs.OnNext(new TodoItem("c"));
                    obs.OnCompleted();
                }
                return(Disposable.Empty);
            }));
            var observable = LoadCommand.ThrownExceptions.Select(ex => new UserError(ex.Message, recoveryOptions: new[] { RecoveryCommand.Yes, RecoveryCommand.Cancel }));

            //_LastError = observable.ToProperty(this, x => x.LastError);

            observable.SelectMany(UserError.Throw).Subscribe(result =>
            {
                //this.RaisePropertyChanged("HasError");
                switch (result)
                {
                case RecoveryOptionResult.CancelOperation:
                    return;

                case RecoveryOptionResult.RetryOperation:
                    LoadCommand.Execute(null);
                    break;
                }
            });
            LoadCommand.Subscribe(Items.Add);
        }