当前位置: 首页>>代码示例>>C#>>正文


C# ReactiveCommand.Subscribe方法代码示例

本文整理汇总了C#中ReactiveCommand.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand.Subscribe方法的具体用法?C# ReactiveCommand.Subscribe怎么用?C# ReactiveCommand.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReactiveCommand的用法示例。


在下文中一共展示了ReactiveCommand.Subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OrderViewModel

        public OrderViewModel()
        {
            this.DisplayName = "Add/Edit Order";

            context = new LittleTravellerDataContext();
            var CanSave = this.Changed.Select(_ => ValidateFields()).StartWith(false);
            SaveCommand = new ReactiveCommand(CanSave);
            SaveCommand.Subscribe(_ => SaveOrder());
            NewOrderNumCommand = new ReactiveCommand();
            NewOrderNumCommand.Subscribe(_ => NewOrderNum());
            CloseTabCommand = new ReactiveCommand();
            CloseTabCommand.Subscribe(_ => TabClosing());
            SaveCommand.Subscribe(_ => SaveOrder());
            var CanAddItem = this.Changed.Select(_ => CanAddItemValidate()).StartWith(false);
            AddItemCommand = new ReactiveCommand(CanAddItem);
            AddItemCommand.Subscribe(_ => AddItem());
            DeleteItemCommand = new ReactiveCommand();
            DeleteItemCommand.OfType<ItemOptionsClass>().Subscribe(item => DeleteItem(item));

            CustomerOptions = (from cs in context.Customers select cs.CompanyName).ToList();
            SeasonOptions = context.Seasons.ToList();
            SizeTypeOptions = context.SizeTypes.ToList();
            ItemOptions = new ReactiveCollection<ItemOptionsClass>();
            _orderItems = new ObservableCollection<ItemOptionsClass>();
            AllSeasonsChecked = true;
            AllSizeTypesChecked = true;

            FillItemOptions();
        }
开发者ID:cab-codespring,项目名称:LitTravMaint,代码行数:29,代码来源:OrderViewModel.cs

示例2: ReactiveCommandAllFlow

        public void ReactiveCommandAllFlow()
        {
            var testScheduler = new TestScheduler();
            var @null = (object)null;
            var recorder1 = testScheduler.CreateObserver<object>();
            var recorder2 = testScheduler.CreateObserver<object>();

            var cmd = new ReactiveCommand();
            cmd.Subscribe(recorder1);
            cmd.Subscribe(recorder2);

            cmd.CanExecute().Is(true);
            cmd.Execute(); testScheduler.AdvanceBy(10);
            cmd.Execute(); testScheduler.AdvanceBy(10);
            cmd.Execute(); testScheduler.AdvanceBy(10);

            cmd.Dispose();
            cmd.CanExecute().Is(false);

            cmd.Dispose(); // dispose again

            recorder1.Messages.Is(
                OnNext(0, @null),
                OnNext(10, @null),
                OnNext(20, @null),
                OnCompleted<object>(30));

            recorder2.Messages.Is(
                OnNext(0, @null),
                OnNext(10, @null),
                OnNext(20, @null),
                OnCompleted<object>(30));
        }
开发者ID:wada811,项目名称:ReactiveProperty,代码行数:33,代码来源:ReactiveCommandTest.cs

示例3: OpenDatabaseViewModel

        public OpenDatabaseViewModel(
            INavigationService navigationService,
            IDatabaseInfoRepository databaseInfoRepository,
            ICanSHA256Hash hasher,
            IDialogService dialogService,
            IPWDatabaseDataSource databaseSource,
            ICache cache)
        {
            _cache = cache;
            _databaseSource = databaseSource;
            _dialogService = dialogService;
            _databaseInfoRepository = databaseInfoRepository;
            _hasher = hasher;
            _navigationService = navigationService;
            var canHitOpen = this.WhenAny(
                vm => vm.Password, 
                vm => vm.KeyFileName,
                (p, k) => !string.IsNullOrEmpty(p.Value) || !string.IsNullOrEmpty(k.Value));

            OpenCommand = new ReactiveCommand(canHitOpen);
            OpenCommand.Subscribe(OpenDatabase);

            GetKeyFileCommand = new ReactiveCommand();
            GetKeyFileCommand.Subscribe(GetKeyFile); 
            
            ClearKeyFileCommand = new ReactiveCommand();
            ClearKeyFileCommand.Subscribe(ClearKeyFile);

            IObservable<string> keyFileNameChanged = this.WhenAny(vm => vm.KeyFileName, kf => kf.Value);
            keyFileNameChanged.Subscribe(v => ClearKeyFileButtonIsVisible = !string.IsNullOrWhiteSpace(v));
            keyFileNameChanged.Subscribe(v => GetKeyFileButtonIsVisible = string.IsNullOrWhiteSpace(v));
        }
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:32,代码来源:OpenDatabaseViewModel.cs

示例4: SerializationViewModel

        public SerializationViewModel()
        {
            // Observable sequence to ObservableCollection
            Items = Observable.Interval(TimeSpan.FromSeconds(1))
                .Take(30)
                .ToReactiveCollection();
            IsChecked = new ReactiveProperty<bool>();
            SelectedIndex = new ReactiveProperty<int>();
            Text = new ReactiveProperty<string>();
            SliderPosition = new ReactiveProperty<int>();

            var serializedString = new ReactiveProperty<string>(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);
            Serialize = serializedString.Select(x => x == null).ToReactiveCommand();
            Deserialize = serializedString.Select(x => x != null).ToReactiveCommand();

            // Click Serialize Button
            Serialize.Subscribe(_ =>
            {
                // Serialize ViewModel's all ReactiveProperty Values.
                // return value is string that Serialize by DataContractSerializer.
                serializedString.Value = SerializeHelper.PackReactivePropertyValue(this); // this = ViewModel
            });

            // Click Deserialize Button
            Deserialize.Subscribe(_ =>
            {
                // Deserialize to target ViewModel.
                // Deseirlization order is same as DataContract.
                // Can control DataMemberAttribute's Order Property.
                // more info see http://msdn.microsoft.com/en-us/library/ms729813.aspx
               SerializeHelper.UnpackReactivePropertyValue(this, serializedString.Value);

                serializedString.Value = null; // push to command canExecute
            });
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:35,代码来源:SerializationViewModel.cs

示例5: ViewModel2

        public ViewModel2()
        {
            SearchResults = new ReactiveList<FlickrPhoto>();
            var canSearch = this.WhenAny(x => x.SearchTerm, x => !String.IsNullOrWhiteSpace(x.Value));

            Search = ReactiveCommand.CreateAsyncTask(canSearch, async _ =>  {  return await GetSearchResultFromBing(this.SearchTerm); });
            LoadMoreItems = ReactiveCommand.CreateAsyncTask(canSearch, async x => { return await LoadMore((int)x);  });

            Search.Subscribe(results =>
            {
                SearchResults.Clear();
                foreach (var item in results)
                {
                    SearchResults.Add(item);
                }
            });

            LoadMoreItems.Subscribe(results =>
            {
                foreach (var item in results)
                {
                    SearchResults.Add(item);
                }
            });

            Search.ThrownExceptions.Subscribe(ex => { UserError.Throw("Potential network connectivity Error", ex); });
            LoadMoreItems.ThrownExceptions.Subscribe(ex => { UserError.Throw("Problem when downloading additional items", ex); });

            this.WhenAnyValue(x => x.SearchTerm)
                .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
                .InvokeCommand(this, x => x.Search);

            //SearchTerm = "british cat";
        }
开发者ID:afrog33k,项目名称:SharpPlayground,代码行数:34,代码来源:ViewModel2.cs

示例6: SessionViewModel

        public SessionViewModel(SessionModel model ,IPersonFactory<Person> personFactory)
        {
            _model = model.ThrowIfNull("model");
            _personFactory = personFactory.ThrowIfNull("personFactory");

            AddNewPersonCommand = new ReactiveCommand();
            AddNewPersonCommand.Subscribe(dontcare =>
                _model.Participants.Add(_personFactory.GetNewPerson(Participants.Count)));

            Participants = _model.Participants
                                    .CreateDerivedCollection(x => new ParticipantViewModel(x));

            Participants.ChangeTrackingEnabled = true;

            var deleteCanExecute = Observable.Merge(Participants.ItemChanged
                                                 .Select(_ => Participants.Any(p => p.IsSelected)),
                                             Participants.CollectionCountChanged
                                             .Select(_ => Participants.Any(p=> p.IsSelected)));

            DeleteSelectedCommand = new ReactiveCommand
                (
                       deleteCanExecute
                );
            DeleteSelectedCommand.Subscribe(
                x =>
                    {
                        RemoveSelected();
                    }
                );

            AddNewPersonCommand.Execute(null);
        }
开发者ID:asizikov,项目名称:PiratesBay,代码行数:32,代码来源:SessionViewModel.cs

示例7: OpenFileTabContentViewModel

 public OpenFileTabContentViewModel(IDialogService dialogService)
 {
     this.dialogService = dialogService;
     
     openFileCommand = ReactiveCommand.Create();
     openFileCommand.Subscribe(_ => OpenFile());
 }
开发者ID:402214782,项目名称:mvvm-dialogs,代码行数:7,代码来源:OpenFileTabContentViewModel.cs

示例8: CreateActivityViewModel

        public CreateActivityViewModel()
        {
            int result = 0;
            var canSave = this.WhenAny(
                x => x.Name,
                x => x.ExpectedEffort,
                (n, e) => !string.IsNullOrWhiteSpace(n.Value) && int.TryParse(e.Value, out result));
            SaveCommand = new ReactiveCommand(canSave, DispatcherScheduler.Instance);
            SaveCommand.Subscribe(o => Save());

            var prototypeActivity = this.Changed
                .Where(c => c.PropertyName == "Name")
                .Throttle(TimeSpan.FromMilliseconds(500))
                .Select(c => Name)
                .ObserveOnDispatcher()
                // Access to the ActivityRepository synchronized on the main thread... maybe not the best idea
                .Select(n => DomainContext.Activities.Where(a => a.Name == n).OrderByDescending(a => a.CreationTime).FirstOrDefault())
                .Where(a => a != null);

            prototypeActivity
                .Select(a => a.Tags.Select(t => t.Name).ToArray())
                .ObserveOnDispatcher()
                .Subscribe(t => Tags = t);

            prototypeActivity
                .Where(a => string.IsNullOrWhiteSpace(ExpectedEffort))
                .Select(a => a.ExpectedEffort.ToString())
                .ObserveOnDispatcher()
                .Subscribe(ee => ExpectedEffort = ee);

            CancelCommand = new RelayCommand(Cancel);
        }
开发者ID:kewkie,项目名称:WorkBalance,代码行数:32,代码来源:CreateActivityViewModel.cs

示例9: InsertGistViewModel

        public InsertGistViewModel()
        {
            //var client = new GitHubClient() { Username = "octocat", Password = "FillMeInHere" };

            var privateImage = new BitmapImage(new Uri(@"pack://application:,,,/data/private.png"));
            var publicImage = new BitmapImage(new Uri(@"pack://application:,,,/data/public.png"));

            _PublicPrivateIcon = this.WhenAny(x => x.IsPrivateGist, x => x.Value)
                .Select(x => x ? privateImage : publicImage)
                .ToProperty(this, x => x.PublicPrivateIcon);

            CreateGist = new ReactiveAsyncCommand();

            CreateGist.RegisterAsyncObservable(_ => client.CreateGist(SelectionText, !IsPrivateGist))
                .Select(x => x.html_url)
                .BindTo(this, x => x.LastGistUrl);

            CopyToClipboard = new ReactiveCommand(
                this.WhenAny(x => x.LastGistUrl, x => !String.IsNullOrWhiteSpace(x.Value)));

            CopyToClipboard.Subscribe(_ => Clipboard.SetText(LastGistUrl));

            this.WhenAny(x => x.SelectionText, x => x.Value)
                .Where(_ => LastGistUrl != null)
                .Subscribe(_ => LastGistUrl = null);
        }
开发者ID:paulcbetts,项目名称:GistForVS,代码行数:26,代码来源:InsertGistViewModel.cs

示例10: SetConfigurationMenu

        void SetConfigurationMenu(MainWindowViewModel viewModel)
        {
            ConfigurationContextMenu.Items.Clear();
            foreach (var item in viewModel.Configrations)
            {
                ConfigurationContextMenu.Items.Add(new MenuItem { FontSize = 12, Header = item.Item1, Command = item.Item2 });
            }
            ConfigurationContextMenu.Items.Add(new Separator());
            var saveCommand = new ReactiveCommand();
            saveCommand.Subscribe(_ =>
            {
                var dialog = new Microsoft.Win32.SaveFileDialog();
                dialog.FilterIndex = 1;
                dialog.Filter = "JSON Configuration|*.json";
                dialog.InitialDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "configuration");

                if (dialog.ShowDialog() == true)
                {
                    var fName = dialog.FileName;
                    if (!fName.EndsWith(".json")) fName = fName + ".json";
                    viewModel.SaveCurrentConfiguration(fName);
                    viewModel.LoadConfigurations();
                    SetConfigurationMenu(viewModel); // reset
                }
            });
            ConfigurationContextMenu.Items.Add(new MenuItem { FontSize = 12, Header = "Save...", Command = saveCommand });
        }
开发者ID:neuecc,项目名称:PhotonWire,代码行数:27,代码来源:MainWindow.xaml.cs

示例11: RepositoryOutlinerVm

        public RepositoryOutlinerVm(RepositoryVm repos)
            : base(string.Empty, RepositoryOutlinerItemType.Root, null, repos, null)
        {
            Debug.Assert(repos != null);
            _repos = repos;

            SelectedItem = new ReactiveProperty<RepositoryOutlinerItemVm>()
                .AddTo(MultipleDisposable);

            // 各項目のルートノードを配置する
            _localBranch =
                new RepositoryOutlinerItemVm("Local", RepositoryOutlinerItemType.LocalBranchRoot, null, repos, this)
                    .AddTo(MultipleDisposable);

            _remoteBranch =
                new RepositoryOutlinerItemVm("Remote", RepositoryOutlinerItemType.RemoteBranchRoot, null, repos, this)
                    .AddTo(MultipleDisposable);

            Children.AddOnScheduler(_localBranch);
            Children.AddOnScheduler(_remoteBranch);

            UpdateBranchNodes(_localBranch, repos.LocalBranches, false);
            UpdateBranchNodes(_remoteBranch, repos.RemoteBranches, true);

            repos.LocalBranches.CollectionChangedAsObservable()
                .Subscribe(_ => UpdateBranchNodes(_localBranch, repos.LocalBranches, false))
                .AddTo(MultipleDisposable);

            repos.RemoteBranches.CollectionChangedAsObservable()
                .Subscribe(_ => UpdateBranchNodes(_remoteBranch, repos.RemoteBranches, true))
                .AddTo(MultipleDisposable);

            SwitchBranchCommand = new ReactiveCommand().AddTo(MultipleDisposable);
            SwitchBranchCommand.Subscribe(_ => SwitchBranch()).AddTo(MultipleDisposable);
        }
开发者ID:YoshihiroIto,项目名称:Anne,代码行数:35,代码来源:RepositoryOutlinerVm.cs

示例12: ReactivePropertyBasicsPageViewModel

        public ReactivePropertyBasicsPageViewModel()
        {
            // mode is Flags. (default is all)
            // DistinctUntilChanged is no push value if next value is same as current
            // RaiseLatestValueOnSubscribe is push value when subscribed
            var allMode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe;

            // binding value from UI Control
            // if no set initialValue then initialValue is default(T). int:0, string:null...
            InputText = new ReactiveProperty<string>(initialValue: "", mode: allMode);

            // send value to UI Control
            DisplayText = InputText
                .Select(s => s.ToUpper())       // rx query1
                .Delay(TimeSpan.FromSeconds(1)) // rx query2
                .ToReactiveProperty();          // convert to ReactiveProperty

            ReplaceTextCommand = InputText
                .Select(s => !string.IsNullOrEmpty(s))   // condition sequence of CanExecute
                .ToReactiveCommand(); // convert to ReactiveCommand

            // ReactiveCommand's Subscribe is set ICommand's Execute
            // ReactiveProperty.Value set is push(& set) value
            ReplaceTextCommand.Subscribe(_ => InputText.Value = "Hello, ReactiveProperty!");
        }
开发者ID:neuecc,项目名称:ReactiveProperty,代码行数:25,代码来源:ReactivePropertyBasicsPageViewModel.cs

示例13: MainWindowViewModel

        public MainWindowViewModel(ISentenceFactory sentenceFactory)
        {
            _sentenceFactory = sentenceFactory;

              CreateSentenceCommand = new ReactiveCommand(this.WhenAny(x => x.NewSentence, x => !string.IsNullOrEmpty(x.Value)));
              CreateSentenceCommand.Subscribe(_ => CreateSentence());
        }
开发者ID:darkmyst,项目名称:DnDEventLog,代码行数:7,代码来源:MainWindowViewModel.cs

示例14: MainViewModel

        public MainViewModel()
        {
            _informationEngine = new InformationEngine();
            _sessionViewModels =
                _informationEngine.Sessions.CreateDerivedCollection(x => new SessionViewModel(x) as ISessionViewModel);
            ((IEditableCollectionView) (CollectionViewSource.GetDefaultView(_sessionViewModels)))
                .NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;

            _showInitializationErrorMessage = () => MessageBox.Show(
                "Bei der Initialisierung des Receivers ist ein Fehler aufgetreten.\n" +
                "Bitte schließen Sie die Session und starten den Receiver neu.",
                "Fehler");

            _showCloseSessionErrorMessage = () => MessageBox.Show(
                "Beim Schließen der Session trat ein Fehler auf.",
                "Fehler");

            StartNewSessionCommand = new ReactiveCommand();
            StartNewSessionCommand.Subscribe(_ => StartNewSession());

            InitializeReceiverCommand = new ReactiveAsyncCommand();
            InitializeReceiverCommand.RegisterAsyncAction(x => InitializeReceiver((Tuple<Guid, IReceiver>) x));
            InitializeReceiverCommand.ThrownExceptions.Subscribe(
                ex => _showInitializationErrorMessage());

            CloseSessionCommand = new ReactiveCommand();
            CloseSessionCommand.Subscribe(x => CloseSession((ISessionViewModel) x));
            CloseSessionCommand.ThrownExceptions.Subscribe(ex => _showCloseSessionErrorMessage());
        }
开发者ID:GraphalyzerPro,项目名称:GraphalyzerPro,代码行数:29,代码来源:MainViewModel.cs

示例15: MyPageViewModel

        public MyPageViewModel(ITicketService ticketService, ITicketMapper mapper)
        {
            _ticketService = ticketService;
            _mapper = mapper;

            LoadTickets = new ReactiveAsyncCommand(null, 1, RxApp.DeferredScheduler);

            LoadTickets.RegisterAsyncFunction(x => loadTickets())
                .ToProperty(this, x => x.Tickets);

            Observable.Interval(TimeSpan.FromSeconds(10), RxApp.DeferredScheduler)
                    .InvokeCommand(LoadTickets);
            LoadTickets.Execute(null);

            _redmineBaseUrl = ConfigurationManager.AppSettings["Redmine.BaseRedmineUrl"];

            SortBy = new List<SortByModel>()
            {
                new SortByModel("Project", c => c.Project),
                new SortByModel("Due date", c=> c.DueDate),
                new SortByModel("Priority", c => c.Priority),
            };

            SortByCommand = new ReactiveCommand(this.WhenAny(c => c.Tickets,
                                                                                                            ((tickets) => tickets.Value != null && tickets.Value.Count > 0)));

            SortByCommand.Subscribe(c => sortTickets((SortByModel)c));
        }
开发者ID:sTodorov,项目名称:bugmine,代码行数:28,代码来源:MyPageViewModel.cs


注:本文中的ReactiveCommand.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。