本文整理汇总了C#中ReactiveCommand.RegisterAsyncFunction方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand.RegisterAsyncFunction方法的具体用法?C# ReactiveCommand.RegisterAsyncFunction怎么用?C# ReactiveCommand.RegisterAsyncFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveCommand
的用法示例。
在下文中一共展示了ReactiveCommand.RegisterAsyncFunction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoginWidgetViewModel
public LoginWidgetViewModel(ILogPeopleIn loginManager)
{
Login = new ReactiveCommand(this.WhenAnyValue(x => x.Username, y => y.Password, (x, y) => !string.IsNullOrWhiteSpace(x) && !string.IsNullOrWhiteSpace(y)));
Login.RegisterAsyncFunction(_ => loginManager.TryLogin(Username, Password))
.Subscribe(x => Status = x ? "Success!" : "Failed. Please try again.");
Login.IsExecuting.Where(x => x).Select(_ => "Working...").BindTo(this, x => x.Status);
_isEnabled = Login.IsExecuting.Select(x => !x).ToProperty(this, x => x.IsEnabled);
}
示例2: ViewModel
public ViewModel()
{
//GetItems();
this.delays = new ObservableCollection<int>()
{
1, 2, 3, 4, 5
};
this.selectedDelay = this.delays[1];
var executeSearchCommand = new ReactiveCommand();
var results = executeSearchCommand.RegisterAsyncFunction(s => { return ExecuteSearch(s as string); });
_executeSearchCommand = executeSearchCommand;
this.ObservableForProperty<ViewModel, string>("SearchText")
.Throttle(TimeSpan.FromMilliseconds(800))
.Select(x => x.Value)
.DistinctUntilChanged()
.Where(x => !string.IsNullOrWhiteSpace(x))
.Subscribe(_executeSearchCommand.Execute);
_searchResults = new ObservableAsPropertyHelper<ObservableCollection<Item>>(results, _ => raisePropertyChanged("SearchResults"));
}
示例3: RAFShouldActuallyRunOnTheTaskpool
public void RAFShouldActuallyRunOnTheTaskpool()
{
var deferred = RxApp.MainThreadScheduler;
var taskpool = RxApp.TaskpoolScheduler;
try {
var testDeferred = new CountingTestScheduler(Scheduler.Immediate);
var testTaskpool = new CountingTestScheduler(Scheduler.NewThread);
RxApp.MainThreadScheduler = testDeferred;
RxApp.TaskpoolScheduler = testTaskpool;
var fixture = new ReactiveCommand();
var result = fixture.RegisterAsyncFunction(x => {
Thread.Sleep(1000);
return (int)x*5;
});
fixture.Execute(1);
Assert.Equal(5, result.First());
Assert.True(testDeferred.ScheduledItems.Count >= 1);
Assert.True(testTaskpool.ScheduledItems.Count >= 1);
} finally {
RxApp.MainThreadScheduler = deferred;
RxApp.TaskpoolScheduler = taskpool;
}
}