Ejemplo n.º 1
0
        internal static IDisposable BindToButton <T>(this ReactiveCommand <T> command, T value, ToolStripMenuItem button)
        {
            CompositeDisposable disposable = new CompositeDisposable();

            command
            .CanExecuteChangedAsObservable()
            .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe)
            .Subscribe(_ => button.Enabled = command.CanExecute())
            .AddTo(disposable);

            Observable.FromEvent <EventHandler, EventArgs>(
                h => (s, e) => h(e),
                h => button.Click += h,
                h => button.Click -= h
                )
            .Subscribe(_ => command.Execute(value))
            .AddTo(disposable);

            return(disposable);
        }
Ejemplo n.º 2
0
        internal static IDisposable BindToCheckBox(this ReactiveCommand command, CheckBox checkBox)
        {
            CompositeDisposable disposable = new CompositeDisposable();

            command
            .CanExecuteChangedAsObservable()
            .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe)
            .Subscribe(_ => checkBox.Enabled = command.CanExecute())
            .AddTo(disposable);

            Observable.FromEvent <EventHandler, EventArgs>(
                h => (s, e) => h(e),
                h => checkBox.Click += h,
                h => checkBox.Click -= h
                )
            .Subscribe(_ => command.Execute())
            .AddTo(disposable);

            return(disposable);
        }
Ejemplo n.º 3
0
        public SearchPageViewModel(
            IScheduler scheduler,
            ApplicationLayoutManager applicationLayoutManager,
            NiconicoSession niconicoSession,
            SearchProvider searchProvider,
            PageManager pageManager,
            SearchHistoryRepository searchHistoryRepository
            )
        {
            _scheduler = scheduler;
            ApplicationLayoutManager = applicationLayoutManager;
            NiconicoSession          = niconicoSession;
            SearchProvider           = searchProvider;
            PageManager = pageManager;
            _searchHistoryRepository = searchHistoryRepository;
            HashSet <string> HistoryKeyword = new HashSet <string>();

            foreach (var item in _searchHistoryRepository.ReadAllItems().OrderByDescending(x => x.LastUpdated))
            {
                if (HistoryKeyword.Contains(item.Keyword))
                {
                    continue;
                }

                SearchHistoryItems.Add(new SearchHistoryListItemViewModel(item, this));
                HistoryKeyword.Add(item.Keyword);
            }

            SearchText = new ReactiveProperty <string>(_LastKeyword)
                         .AddTo(_CompositeDisposable);

            TargetListItems = new List <SearchTarget>()
            {
                SearchTarget.Keyword,
                SearchTarget.Tag,
                SearchTarget.Niconama,
            };

            SelectedTarget = new ReactiveProperty <SearchTarget>(_LastSelectedTarget)
                             .AddTo(_CompositeDisposable);

            DoSearchCommand = new ReactiveCommand()
                              .AddTo(_CompositeDisposable);
#if DEBUG
            SearchText.Subscribe(x =>
            {
                Debug.WriteLine($"検索:{x}");
            });
#endif

#if DEBUG
            DoSearchCommand.CanExecuteChangedAsObservable()
            .Subscribe(x =>
            {
                Debug.WriteLine(DoSearchCommand.CanExecute());
            });
#endif



            IsNavigationFailed     = new ReactiveProperty <bool>();
            NavigationFailedReason = new ReactiveProperty <string>();
        }