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


C# ReactiveProperty类代码示例

本文整理汇总了C#中ReactiveProperty的典型用法代码示例。如果您正苦于以下问题:C# ReactiveProperty类的具体用法?C# ReactiveProperty怎么用?C# ReactiveProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AsynchronousViewModel

        public AsynchronousViewModel()
        {
            // Notifier of network connecitng status/count
            var connect = new CountNotifier();
            // Notifier of network progress report
            var progress = new ScheduledNotifier<Tuple<long, long>>(); // current, total

            // skip initialValue on subscribe
            SearchTerm = new ReactiveProperty<string>(mode: ReactivePropertyMode.DistinctUntilChanged);

            // Search asynchronous & result direct bind
            // if network error, use OnErroRetry
            // that catch exception and do action and resubscript.
            SearchResults = SearchTerm
                .Select(async term =>
                {
                    using (connect.Increment()) // network open
                    {
                        return await WikipediaModel.SearchTermAsync(term, progress);
                    }
                })
                .Switch() // flatten
                .OnErrorRetry((HttpRequestException ex) => ProgressStatus.Value = "error occured")
                .ToReactiveProperty();

            // CountChangedStatus : Increment(network open), Decrement(network close), Empty(all complete)
            SearchingStatus = connect
                .Select(x => (x != CountChangedStatus.Empty) ? "loading..." : "complete")
                .ToReactiveProperty();

            ProgressStatus = progress
                .Select(x => string.Format("{0}/{1} {2}%", x.Item1, x.Item2, ((double)x.Item1 / x.Item2) * 100))
                .ToReactiveProperty();
        }
开发者ID:neuecc,项目名称:ReactiveProperty,代码行数:34,代码来源:AsynchronousViewModel.cs

示例2: MainViewModel

        public MainViewModel()
        {
            _directoryToMonitor = new DirectoryInfo(Properties.Settings.Default.DirectoryToObserve);
            _fileEndingFilters = Properties.Settings.Default.FileFilters.Split(' ');
            SearchTerm = new ReactiveProperty<string>();
            _episodes = new ObservableCollection<Episode>();
            _allEpisodes = new List<Episode>();

            var loadedEpisodes = from _ in Observable.Interval(TimeSpan.FromSeconds(5)).Merge(Observable.Return(0L))
                              let files = GetFiles(_directoryToMonitor.ToString(), _fileEndingFilters, SearchOption.AllDirectories)
                              select files.Select(file => new Episode(new FileInfo(file))).ToList();

            loadedEpisodes.Subscribe(files =>
                {
                    _allEpisodes = files;
                });

            var searchClickEvents = SearchTerm.Throttle(TimeSpan.FromMilliseconds(100));

            searchClickEvents.ObserveOn(SynchronizationContext.Current).Subscribe(_ =>
                {
                    var episodes = from episode in _allEpisodes
                                   where IsContainedInFilter(episode.File.Name)
                                   select episode;

                    _episodes.Clear();
                    foreach (var episode in episodes)
                        _episodes.Add(episode);
                });
        }
开发者ID:AndreasPresthammer,项目名称:PiratePlayer,代码行数:30,代码来源:MainViewModel.cs

示例3: 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

示例4: 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

示例5: CombineLatestValuesAreAllTrueTest

        public void CombineLatestValuesAreAllTrueTest()
        {
            var m = ReactivePropertyMode.RaiseLatestValueOnSubscribe;
            var recorder = new TestScheduler().CreateObserver<bool>();

            var x = new ReactiveProperty<bool>(mode: m);
            var y = new ReactiveProperty<bool>(mode: m);
            var z = new ReactiveProperty<bool>(mode: m);

            new[] { x, y, z }.CombineLatestValuesAreAllTrue().Subscribe(recorder);
            recorder.Messages.First().Is(OnNext(0, false));

            x.Value = true; recorder.Messages.Last().Is(OnNext(0, false));
            y.Value = true; recorder.Messages.Last().Is(OnNext(0, false));
            z.Value = true; recorder.Messages.Last().Is(OnNext(0, true));
            y.Value = false; recorder.Messages.Last().Is(OnNext(0, false));
            z.Value = false; recorder.Messages.Last().Is(OnNext(0, false));
            x.Value = true; recorder.Messages.Last().Is(OnNext(0, false));
            z.Value = true; recorder.Messages.Last().Is(OnNext(0, false));
            y.Value = true; recorder.Messages.Last().Is(OnNext(0, true));
            x.Value = false; recorder.Messages.Last().Is(OnNext(0, false));
            y.Value = false; recorder.Messages.Last().Is(OnNext(0, false));
            z.Value = false; recorder.Messages.Last().Is(OnNext(0, false));
            z.Value = true; recorder.Messages.Last().Is(OnNext(0, false));
        }
开发者ID:wada811,项目名称:ReactiveProperty,代码行数:25,代码来源:CombineLatestEnumerableExtensionsTest.cs

示例6: ToReactiveProperty

        public void ToReactiveProperty()
        {
            {
                var rxProp = new ReactiveProperty<int>();
                var calledCount = 0;

                var readRxProp = rxProp.ToReactiveProperty();
                readRxProp.Subscribe(x => calledCount++);

                calledCount.Is(1);
                rxProp.Value = 10;
                calledCount.Is(2);
                rxProp.Value = 10;
                calledCount.Is(2);

                rxProp.SetValueAndForceNotify(10);
                calledCount.Is(2);
            }
            {
                var rxProp = new ReactiveProperty<int>();
                var calledCount = 0;

                var readRxProp = rxProp.ToSequentialReadOnlyReactiveProperty();
                readRxProp.Subscribe(x => calledCount++);

                calledCount.Is(1);
                rxProp.Value = 10;
                calledCount.Is(2);
                rxProp.Value = 10;
                calledCount.Is(2);

                rxProp.SetValueAndForceNotify(10);
                calledCount.Is(3);
            }
        }
开发者ID:neuecc,项目名称:UniRx,代码行数:35,代码来源:_ManualyTest.cs

示例7: SettingsPageViewModel

		public SettingsPageViewModel(PageManager pageManager, IReactiveFolderSettings settings)
			: base(pageManager)
		{
			Settings = settings;

			ReactionCheckInterval = new ReactiveProperty<string>(settings.DefaultMonitorIntervalSeconds.ToString());

			ReactionCheckInterval.Subscribe(x =>
			{
				settings.DefaultMonitorIntervalSeconds = int.Parse(x);
				settings.Save();
			});

			ReactionCheckInterval.SetValidateNotifyError(x => 
			{
				int temp;
				if (false == int.TryParse(x, out temp))
				{
					return "Number Only";
				}

				return null;
			});

		}
开发者ID:tor4kichi,项目名称:ReactiveFolder,代码行数:25,代码来源:SettingsPageViewModel.cs

示例8: 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

示例9: NoRaiseLatestValueOnSubscribe

 public void NoRaiseLatestValueOnSubscribe()
 {
     var rp = new ReactiveProperty<string>(mode: ReactivePropertyMode.DistinctUntilChanged);
     var called = false;
     rp.Subscribe(_ => called = true);
     called.Is(false);
 }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:7,代码来源:ReactivePropertyTest.cs

示例10: MonsterModel

    public MonsterModel(int id)
    {
        this.monsterId = id;

        isSelected = new ReactiveProperty<bool> (false);

        switch (monsterId)
        {
        case 1:
            this.materialColor = Color.red;
            break;
        case 2:
            this.materialColor = Color.green;
            break;
        case 3:
            this.materialColor = Color.blue;
            break;
        case 4:
            this.materialColor = Color.yellow;
            break;
        default:
            this.materialColor = Color.black;
            break;
        }
    }
开发者ID:Yarimizu14,项目名称:_UniRX_MVP_Sample,代码行数:25,代码来源:MonsterModel.cs

示例11: GambitList

            public GambitList( GambitListInfo gambitListInfo )
            {
                this._gambitListInfo = gambitListInfo;

                moveInput = new Subject<Vector3>();
                targets = new ReactiveProperty<object>();
            }
开发者ID:OrangeeZ,项目名称:Crandell,代码行数:7,代码来源:GambitListInfo.cs

示例12: MainPageViewModel

        public MainPageViewModel()
        {
            Message = new ReactiveProperty<string> ();
            Message.Value = "Hello World";

            CateCollection = new List<CateClass>(30).ToObservable().ToReactiveCollection();
        }
开发者ID:gotenkusu48,项目名称:TODOTimer,代码行数:7,代码来源:MainPageViewModel.cs

示例13: EventToReactiveCommandViewModel

 public EventToReactiveCommandViewModel()
 {
     // command called, after converter
     this.SelectFileCommand = new ReactiveCommand<string>();
     // create ReactiveProperty from ReactiveCommand
     this.Message = this.SelectFileCommand
         .Select(x => x + " selected.")
         .ToReactiveProperty();
 }
开发者ID:neuecc,项目名称:ReactiveProperty,代码行数:9,代码来源:EventToReactiveCommandViewModel.cs

示例14: Basic

 public void Basic()
 {
     var prop = new ReactiveProperty<int>(3);
     IReadOnlyObservableList<int> coll = prop.ToLiveLinq<int>().ToReadOnlyObservableList();
     coll.Count.Should().Be(1);
     coll[0].Should().Be(3);
     prop.Value = 4;
     coll[0].Should().Be(4);
 }
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:9,代码来源:Observable2ObservableCollectionTests.cs

示例15: Awake

        void Awake()
        {
            var editPresenter = EditNotesPresenter.Instance;

            this.UpdateAsObservable()
                .Where(_ => Input.GetKeyDown(KeyCode.Escape))
                .Subscribe(_ => Application.Quit());

            var saveActionObservable = this.UpdateAsObservable()
                .Where(_ => KeyInput.CtrlPlus(KeyCode.S))
                .Merge(saveButton.OnClickAsObservable());

            mustBeSaved = Observable.Merge(
                    EditData.BPM.Select(_ => true),
                    EditData.OffsetSamples.Select(_ => true),
                    EditData.MaxBlock.Select(_ => true),
                    editPresenter.RequestForEditNote.Select(_ => true),
                    editPresenter.RequestForAddNote.Select(_ => true),
                    editPresenter.RequestForRemoveNote.Select(_ => true),
                    editPresenter.RequestForChangeNoteStatus.Select(_ => true),
                    Audio.OnLoad.Select(_ => false),
                    saveActionObservable.Select(_ => false))
                .SkipUntil(Audio.OnLoad.DelayFrame(1))
                .Do(unsaved => saveButton.GetComponent<Image>().color = unsaved ? unsavedStateButtonColor : savedStateButtonColor)
                .ToReactiveProperty();

            mustBeSaved.SubscribeToText(messageText, unsaved => unsaved ? "保存が必要な状態" : "");

            saveActionObservable.Subscribe(_ => Save());

            dialogSaveButton.AddListener(
                EventTriggerType.PointerClick,
                (e) =>
                {
                    mustBeSaved.Value = false;
                    saveDialog.SetActive(false);
                    Save();
                    Application.Quit();
                });

            dialogDoNotSaveButton.AddListener(
                EventTriggerType.PointerClick,
                (e) =>
                {
                    mustBeSaved.Value = false;
                    saveDialog.SetActive(false);
                    Application.Quit();
                });

            dialogCancelButton.AddListener(
                EventTriggerType.PointerClick,
                (e) =>
                {
                    saveDialog.SetActive(false);
                });
        }
开发者ID:setchi,项目名称:NoteEditor,代码行数:56,代码来源:SavePresenter.cs


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