示例#1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            e.OldElement?.SendDisappearing();

            if (e.NewElement != null)
            {
                if (e.OldElement == null)
                {
                    Loaded += OnLoaded;
                    Tracker = new BackgroundTracker <FrameworkElement>(BackgroundProperty);
                }

                if (!string.IsNullOrEmpty(Element.AutomationId))
                {
                    SetAutomationId(Element.AutomationId);
                }

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

            TabbedPage oldElement = Element;

            Element = (TabbedPage)element;

            if (oldElement != null)
            {
                oldElement.PropertyChanged -= OnElementPropertyChanged;
                ((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged;
                Control?.GetDescendantsByName <TextBlock>(TabBarHeaderTextBlockName).ForEach(t => { t.AccessKeyInvoked -= AccessKeyInvokedForTab; });
            }

            if (element != null)
            {
                if (Control == null)
                {
                    Control = new FormsPivot {
                        Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"],
                    };

                    Control.SelectionChanged += OnSelectionChanged;

                    Tracker = new BackgroundTracker <Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty)
                    {
                        Element   = (Page)element,
                        Control   = Control,
                        Container = Control
                    };

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

                Control.DataContext = Element;
                OnPagesChanged(Element.Children,
                               new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

                UpdateCurrentPage();
                UpdateToolbarPlacement();
                UpdateToolbarDynamicOverflowEnabled();

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

                if (!string.IsNullOrEmpty(element.AutomationId))
                {
                    Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, element.AutomationId);
                }
            }

            OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
        }
示例#3
0
        public void SetElement(VisualElement element)
        {
            var newPage = element as CarouselPage;

            if (element != null && newPage == null)
            {
                throw new ArgumentException("element must be a CarouselPage");
            }

            CarouselPage oldPage = Element;

            Element = newPage;

            if (oldPage != null)
            {
                oldPage.SendDisappearing();
                ((INotifyCollectionChanged)oldPage.Children).CollectionChanged -= OnChildrenChanged;
                oldPage.PropertyChanged -= OnElementPropertyChanged;
            }

            if (newPage != null)
            {
                if (_tracker == null)
                {
                    _tracker = new BackgroundTracker <FlipView>(BackgroundProperty)
                    {
                        Control = this, Container = this
                    };
                }

                _tracker.Element = newPage;

                // Adding Items triggers the SelectionChanged event,
                // which will reset the CurrentPage unless we tell it to ignore.
                _fromUpdate = true;
                for (var i = 0; i < newPage.Children.Count; i++)
                {
                    Items.Add(newPage.Children[i]);
                }
                _fromUpdate = false;

                ((INotifyCollectionChanged)newPage.Children).CollectionChanged += OnChildrenChanged;
                newPage.PropertyChanged += OnElementPropertyChanged;

                UpdateCurrentPage();
                newPage.SendAppearing();
            }

            OnElementChanged(new ElementChangedEventArgs <CarouselPage>(oldPage, newPage));

            if (!string.IsNullOrEmpty(Element?.AutomationId))
            {
                SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, Element.AutomationId);
            }
        }
示例#4
0
        public void SetElement(VisualElement element)
        {
            if (element != null && !(element is TabbedPage))
            {
                throw new ArgumentException("Element must be a TabbedPage", "element");
            }

            TabbedPage oldElement = Element;

            Element = (TabbedPage)element;

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

            if (element != null)
            {
                if (Control == null)
                {
                    Control = new FormsPivot {
                        Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"],
                    };

                    Control.SelectionChanged += OnSelectionChanged;

                    Tracker = new BackgroundTracker <Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty)
                    {
                        Element = (Page)element, Control = Control, Container = Control
                    };

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

                Control.DataContext = Element;
                OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                UpdateCurrentPage();
                UpdateBarTextColor();
                UpdateBarBackgroundColor();

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

                if (!string.IsNullOrEmpty(element.AutomationId))
                {
                    Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId);
                }
            }


            OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
        }
示例#5
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing || _disposed)
            {
                return;
            }

            if (_tracker != null)
            {
                _tracker.Dispose();
                _tracker = null;
            }

            _disposed = true;
            Page?.SendDisappearing();
            SetElement(null);
        }
        public void SetElement(VisualElement element)
        {
            if (element != null && !(element is NavigationPage))
            {
                throw new ArgumentException("Element must be a Page", nameof(element));
            }

            NavigationPage oldElement = Element;

            Element = (NavigationPage)element;

            if (oldElement != null)
            {
                oldElement.PushRequested      -= OnPushRequested;
                oldElement.PopRequested       -= OnPopRequested;
                oldElement.PopToRootRequested -= OnPopToRootRequested;
                oldElement.InternalChildren.CollectionChanged -= OnChildrenChanged;
                oldElement.PropertyChanged -= OnElementPropertyChanged;
            }

            if (element != null)
            {
                if (_container == null)
                {
                    _container = new PageControl();
                    _container.PointerPressed += OnPointerPressed;
                    _container.SizeChanged    += OnNativeSizeChanged;
                    _container.BackClicked    += OnBackClicked;

                    Tracker = new BackgroundTracker <PageControl>(Control.BackgroundProperty)
                    {
                        Element = (Page)element, Container = _container
                    };

                    SetPage(Element.CurrentPage, false, false);

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

                _container.DataContext = Element.CurrentPage;

                UpdatePadding();
                LookupRelevantParents();
                UpdateTitleColor();
                UpdateNavigationBarBackground();
                UpdateToolbarPlacement();

                // Enforce consistency rules on toolbar (show toolbar if top-level page is Navigation Page)
                _container.ShouldShowToolbar = _parentMasterDetailPage == null && _parentTabbedPage == null;
                if (_parentTabbedPage != null)
                {
                    Element.Appearing += OnElementAppearing;
                }

                Element.PropertyChanged    += OnElementPropertyChanged;
                Element.PushRequested      += OnPushRequested;
                Element.PopRequested       += OnPopRequested;
                Element.PopToRootRequested += OnPopToRootRequested;
                Element.InternalChildren.CollectionChanged += OnChildrenChanged;

                if (!string.IsNullOrEmpty(Element.AutomationId))
                {
                    _container.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, Element.AutomationId);
                }

                PushExistingNavigationStack();
            }

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