/// <summary>
		/// Sets the view pager for this instance.
		/// </summary>
		/// <param name="pager">The pager.</param>
		/// <param name="tabProviderFactory">The factory to use to select the correct tab provider for the given
		/// pager, and equally as a factory for more complex tab providers to delegate to if they want to reuse
		/// .  This also then is set on the .</param>
		/// <exception cref="System.ArgumentException">ViewPager does not have adapter instance.;pager</exception>
		public void SetViewPager(ViewPager pager, TabProviderFactory tabProviderFactory = null)
		{
			if (pager == null)
				return;
			if (pager.Adapter == null)
			{
				throw new ArgumentException("ViewPager does not have adapter instance.", "pager");
			}

			//the property returns the default factory if set to null here.
			_tabProviderFactory = tabProviderFactory;

			//changes made here to be more tolerant of being set to the same pager or to a pager with
			//the same adapter, or to the same pager with a different adapter.
			if (_pager != pager)
			{
				if (_pager != null)
				{
					pager.PageScrolled -= pager_PageScrolled;
					pager.PageScrollStateChanged -= pager_PageScrollStateChanged;
					pager.PageSelected -= pager_PageSelected;
				}
				this._pager = pager;
				pager.PageScrolled += pager_PageScrolled;
				pager.PageScrollStateChanged += pager_PageScrollStateChanged;
				pager.PageSelected += pager_PageSelected;
			}

			if (_adapter != pager.Adapter)
			{
				if (_adapter != null && _observer != null)
				{
					_adapter.UnregisterDataSetObserver(_observer);
				}

				_adapter = pager.Adapter;
				_tabProviderFactory = tabProviderFactory;
				//re-create the Lazys for the default text and tab providers
				_textTabProvider = new Lazy<ITabProvider>(() => TabProviderFactory.CreateTextTabProvider(Context, _adapter));
				_iconTabProvider = new Lazy<ITabProvider>(() => TabProviderFactory.CreateIconTabProvider(Context, _adapter));
				//avoid recycling any previous views, because we've changed adapters.
				_tabsContainer.RemoveAllViews();

				var newProvider = TabProviderFactory.CreateTabProvider(Context, _adapter);
				if (newProvider != _tabProvider && _tabProvider != null)
				{
					//good housekeeping
					_tabProvider.TabUpdated -= _tabProvider_TabUpdated;
					_tabProvider.TabUpdateRequired -= _tabProvider_TabUpdateRequired;
				}

				_tabProvider = newProvider;
				_tabProvider.TabUpdated += _tabProvider_TabUpdated;
				_tabProvider.TabUpdateRequired += _tabProvider_TabUpdateRequired;

				if (_observer == null)
					_observer = new PagerAdapterDataSetObserver(this);

				_adapter.RegisterDataSetObserver(_observer);
			}


			NotifyDataSetChanged();
		}
        /// <summary>
        /// Sets the view pager for this instance, from this the control inherits the PagerAdapter and then
        /// derives the <see cref="ITabProvider"/> - unless you also pass a custom <see cref="TabProviderFactory"/>
        /// in the <paramref name="tabProviderFactory"/> .
        /// </summary>
        /// <param name="pager">The pager.</param>
        /// <param name="tabProviderFactory">The factory to use to select the correct tab provider for the given
        /// pager, and equally as a factory for more complex tab providers to delegate to if they want to reuse
        /// .  This also then is set on the .</param>
        /// <exception cref="System.ArgumentException">ViewPager does not have adapter instance.;pager</exception>
        public void SetViewPager(ViewPager pager, TabProviderFactory tabProviderFactory = null)
        {
            if (pager == null)
            {
                return;
            }
            if (pager.Adapter == null)
            {
                throw new ArgumentException("ViewPager does not have adapter instance.", "pager");
            }

            //the property returns the default factory if set to null here.
            _tabProviderFactory = tabProviderFactory;

            //changes made here to be more tolerant of being set to the same pager or to a pager with
            //the same adapter, or to the same pager with a different adapter.
            if (_pager != pager)
            {
                if (_pager != null)
                {
                    pager.PageScrolled           -= pager_PageScrolled;
                    pager.PageScrollStateChanged -= pager_PageScrollStateChanged;
                    pager.PageSelected           -= pager_PageSelected;
                }
                this._pager                   = pager;
                pager.PageScrolled           += pager_PageScrolled;
                pager.PageScrollStateChanged += pager_PageScrollStateChanged;
                pager.PageSelected           += pager_PageSelected;
            }

            if (_adapter != pager.Adapter)
            {
                if (_adapter != null && _observer != null)
                {
                    _adapter.UnregisterDataSetObserver(_observer);
                }

                _adapter            = pager.Adapter;
                _tabProviderFactory = tabProviderFactory;
                //re-create the Lazys for the default text and tab providers
                _textTabProvider = new Lazy <ITabProvider>(() => TabProviderFactory.CreateTextTabProvider(Context, _adapter));
                _iconTabProvider = new Lazy <ITabProvider>(() => TabProviderFactory.CreateIconTabProvider(Context, _adapter));
                //avoid recycling any previous views, because we've changed adapters.
                _tabsContainer.RemoveAllViews();

                var newProvider = TabProviderFactory.CreateTabProvider(Context, _adapter);
                if (newProvider != _tabProvider && _tabProvider != null)
                {
                    //good housekeeping
                    _tabProvider.TabUpdated        -= _tabProvider_TabUpdated;
                    _tabProvider.TabUpdateRequired -= _tabProvider_TabUpdateRequired;
                }

                _tabProvider                    = newProvider;
                _tabProvider.TabUpdated        += _tabProvider_TabUpdated;
                _tabProvider.TabUpdateRequired += _tabProvider_TabUpdateRequired;

                if (_observer == null)
                {
                    _observer = new PagerAdapterDataSetObserver(this);
                }

                _adapter.RegisterDataSetObserver(_observer);
            }


            NotifyDataSetChanged();
        }