Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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 = (global::Windows.UI.Xaml.Style)global::Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"],
                    };

                    Control.SelectionChanged += OnSelectionChanged;

                    Tracker = new BackgroundTracker <Pivot>(global::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(global::Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, element.AutomationId);
                }
            }

            OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
        }
Exemplo n.º 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(global::Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, Element.AutomationId);
            }
        }
Exemplo n.º 4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing || _disposed)
            {
                return;
            }

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

            _disposed = true;
            Page?.SendDisappearing();
            SetElement(null);
        }