本文整理汇总了C#中ReactiveList.InsertRange方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.InsertRange方法的具体用法?C# ReactiveList.InsertRange怎么用?C# ReactiveList.InsertRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.InsertRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrdersListViewModel
public OrdersListViewModel()
{
_ordersRepository = new OrdersWebRepository ();
_connectivity = CrossConnectivity.Current;
Orders = new ReactiveList<OrderViewModel>();
// Initial connectivity availability
CanLoadOrders = _connectivity.IsConnected;
// Convert a .NET event to an observable
// and subscribe to an observer *anonymous delegate extension*.
IObservable<EventPattern<ConnectivityChangedEventArgs>> connectivityChangedObservable =
Observable.FromEventPattern<ConnectivityChangedEventArgs>(
_connectivity,
"ConnectivityChanged",
RxApp.MainThreadScheduler);
// When the IConnectivity.ConnectivityChanged event is raised
// the observable will push me the ConnectivityChangedEventArgs.
_connectivityChangedDisposable = connectivityChangedObservable.Subscribe(evt => {
// Set if we can load orders
CanLoadOrders = evt.EventArgs.IsConnected;
});
// Cool stuff! ReactiveUI offers some Rx helpers.
// When the CanLoadOrders property changes let me know.
IObservable<bool> canLoadOrdersObservable =
this.WhenAny(x => x.CanLoadOrders, x => x.Value);
// More Cool stuff! ReactiveCommands have built-in support for background
// operations. RxCmd guarantees that this block will only run exactly
// once at a time, and that the CanExecute will auto-disable while it
// is running.
LoadOrdersCommand = ReactiveCommand.CreateAsyncTask(
canLoadOrdersObservable,
async _ =>
{
return await _ordersRepository.GetAsync();;
});
// And if that is not Cool stuff! ReactiveCommands are themselves IObservables, whose value
// are the results from the async method, guaranteed to arrive on the UI
// thread. We're going to take the list of teams that the background
// operation loaded, and put them into our TeamList.
_loadOrdersCommandDisposable = LoadOrdersCommand.ObserveOn(RxApp.MainThreadScheduler).Subscribe(
orders => {
int currentCount = count;
count++;
IEnumerable<OrderViewModel> ordersTranformed = orders.Select(o => {
o.OrderNumber = string.Format("{0} - {1}", o.OrderNumber, currentCount);
return o;
});
Orders.InsertRange(0, ordersTranformed);
},
ex => {
UserError.Throw("Fetching orders exception: " + ex.Message, ex);
});
// Niiiiice! Whenever the CanLoadOrders changes, we're going to wait
// for one second of "dead airtime", then invoke the LoadOrdersCommand
// command.
_canLoadOrdersDisposable = canLoadOrdersObservable
.Where(x => x)
.Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
.InvokeCommand(this, x => x.LoadOrdersCommand);
}