示例#1
0
        public void SetElement(VisualElement element)
        {
            if (element != null && !(element is TabbedPage))
            {
                throw new ArgumentException("Element must be a TabbedPage", "element");
            }

            var oldElement = Page;

            Element = element;

            if (oldElement != null)
            {
                oldElement.PropertyChanged -= OnElementPropertyChanged;
                ((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged;
            }

            if (element != null)
            {
                if (_tracker == null)
                {
                    _tabs = new TabsControl();

                    _canvas = new Canvas();

                    _canvas.ChildrenTransitions = new TransitionCollection
                    {
                        new EntranceThemeTransition()
                    };

                    Tracker = new BackgroundTracker <Canvas>(Panel.BackgroundProperty)
                    {
                        Element   = (Page)element,
                        Control   = _canvas,
                        Container = _canvas
                    };

                    _canvas.Loaded   += OnLoaded;
                    _canvas.Unloaded += OnUnloaded;
                }

                _tabs.DataContext = element;

                OnPagesChanged(Page.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                UpdateCurrentPage();
                UpdateBarTextColor();
                UpdateBarBackgroundColor();

                ((INotifyCollectionChanged)Page.Children).CollectionChanged += OnPagesChanged;
                element.PropertyChanged += OnElementPropertyChanged;
            }

            OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
        }
		public void SetElement(VisualElement element)
		{
			if (element != null && !(element is TabbedPage))
				throw new ArgumentException("Element must be a TabbedPage", "element");

			var oldElement = Page;
			Element = element;

			if (oldElement != null)
			{
				oldElement.PropertyChanged -= OnElementPropertyChanged;
				((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged;
			}

			if (element != null)
			{
				if (_tracker == null)
				{
					_tabs = new TabsControl();

					_canvas = new Canvas();

					_canvas.ChildrenTransitions = new TransitionCollection
					{
						new EntranceThemeTransition()
					};

					Tracker = new BackgroundTracker<Canvas>(Panel.BackgroundProperty)
					{
						Element = (Page)element,
						Control = _canvas,
						Container = _canvas
					};

					_canvas.Loaded += OnLoaded;
					_canvas.Unloaded += OnUnloaded;
				}

				_tabs.DataContext = element;

				OnPagesChanged(Page.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
				UpdateCurrentPage();
				UpdateBarTextColor();
				UpdateBarBackgroundColor();

				((INotifyCollectionChanged)Page.Children).CollectionChanged += OnPagesChanged;
				element.PropertyChanged += OnElementPropertyChanged;
			}

			OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
		}