本文整理汇总了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();
}
示例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);
});
}
示例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
});
}
示例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!");
}
示例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));
}
示例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);
}
}
示例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;
});
}
示例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);
}
示例9: NoRaiseLatestValueOnSubscribe
public void NoRaiseLatestValueOnSubscribe()
{
var rp = new ReactiveProperty<string>(mode: ReactivePropertyMode.DistinctUntilChanged);
var called = false;
rp.Subscribe(_ => called = true);
called.Is(false);
}
示例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;
}
}
示例11: GambitList
public GambitList( GambitListInfo gambitListInfo )
{
this._gambitListInfo = gambitListInfo;
moveInput = new Subject<Vector3>();
targets = new ReactiveProperty<object>();
}
示例12: MainPageViewModel
public MainPageViewModel()
{
Message = new ReactiveProperty<string> ();
Message.Value = "Hello World";
CateCollection = new List<CateClass>(30).ToObservable().ToReactiveCollection();
}
示例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();
}
示例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);
});
}