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


C# ReactiveList.InsertRange方法代码示例

本文整理汇总了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);
		}
开发者ID:xplatsolutions,项目名称:ReactiveX-Demo,代码行数:68,代码来源:OrdersListViewModel.cs


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