public void SetElement(VisualElement element) { if (element != null && !(element is NavigationPage)) { throw new ArgumentException("Element must be a Page", "element"); } NavigationPage oldElement = Element; Element = (NavigationPage)element; if (oldElement != null) { oldElement.PushRequested -= OnPushRequested; oldElement.PopRequested -= OnPopRequested; 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(); Element.PropertyChanged += OnElementPropertyChanged; Element.PushRequested += OnPushRequested; Element.PopRequested += OnPopRequested; Element.InternalChildren.CollectionChanged += OnChildrenChanged; if (!string.IsNullOrEmpty(Element.AutomationId)) { _container.SetValue(AutomationProperties.AutomationIdProperty, Element.AutomationId); } PushExistingNavigationStack(); } OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.SendDisappearing(); } if (e.NewElement != null) { if (e.OldElement == null) { Loaded += OnLoaded; Unloaded += OnUnloaded; Tracker = new BackgroundTracker <FrameworkElement>(BackgroundProperty); } if (_loaded) { e.NewElement.SendAppearing(); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); e.OldElement?.SendDisappearing(); if (e.NewElement != null) { if (e.OldElement == null) { // In the previous version not remove it before, This might be cause a add multiple even problem and cause some performance and memory or other problems wehen keep navigate exist page. Loaded -= OnLoaded; Unloaded -= OnUnloaded; Loaded += OnLoaded; Unloaded += OnUnloaded; Tracker = new BackgroundTracker <FrameworkElement>(BackgroundProperty); } if (_loaded) { e.NewElement.SendAppearing(); } } }
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) { ((IPageController)oldPage).SendDisappearing(); ((INotifyCollectionChanged)oldPage.Children).CollectionChanged -= OnChildrenChanged; oldPage.PropertyChanged -= OnElementPropertyChanged; } if (newPage != null) { if (_tracker == null) { _tracker = new BackgroundTracker <FlipView>(BackgroundProperty) { Control = 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(); ((IPageController)newPage).SendAppearing(); } OnElementChanged(new ElementChangedEventArgs <CarouselPage>(oldPage, newPage)); if (!string.IsNullOrEmpty(Element?.AutomationId)) { SetValue(AutomationProperties.AutomationIdProperty, Element.AutomationId); } }
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.HeaderTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPageHeader"]; Control.ItemTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPage"]; 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)); }
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) { TabbedPage oldElement = _page; _page = (TabbedPage)element; _tracker = new BackgroundTracker<Control>(BackgroundProperty) { Model = _page, Element = this }; DataContext = element; _page.PropertyChanged += OnPropertyChanged; Loaded += (sender, args) => ((IPageController)_page).SendAppearing(); Unloaded += (sender, args) => ((IPageController)_page).SendDisappearing(); OnElementChanged(new VisualElementChangedEventArgs(_page, element)); }
protected virtual void Dispose(bool disposing) { if (!disposing || _disposed) { return; } if (_tracker != null) { _tracker.Dispose(); _tracker = null; } _disposed = true; PageController?.SendDisappearing(); SetElement(null); }
protected override void ConnectHandler(PageControl nativeView) { base.ConnectHandler(nativeView); var virtualView = VirtualViewWithValidation(); nativeView.PointerPressed += OnPointerPressed; nativeView.SizeChanged += OnNativeSizeChanged; Tracker = new BackgroundTracker <PageControl>(Control.BackgroundProperty) { Element = virtualView, Container = NativeView }; SetPage(virtualView.CurrentPage, false, false); nativeView.Loaded += OnLoaded; nativeView.Unloaded += OnUnloaded; nativeView.DataContext = virtualView.CurrentPage; // Move this somewhere else LookupRelevantParents(); // Enforce consistency rules on toolbar (show toolbar if top-level page is Navigation Page) nativeView.ShouldShowToolbar = _parentFlyoutPage == null && _parentTabbedPage == null; if (_parentTabbedPage != null) { virtualView.Appearing += OnElementAppearing; } virtualView.PushRequested += OnPushRequested; virtualView.PopRequested += OnPopRequested; virtualView.PopToRootRequested += OnPopToRootRequested; virtualView.InternalChildren.CollectionChanged += OnChildrenChanged; if (!string.IsNullOrEmpty(virtualView.AutomationId)) { nativeView.SetValue(Microsoft.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, virtualView.AutomationId); } PushExistingNavigationStack(); }
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(); #if WINDOWS_UWP // 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; } #endif 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)); }
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) { ((IPageController)oldPage).SendDisappearing(); ((INotifyCollectionChanged)oldPage.Children).CollectionChanged -= OnChildrenChanged; oldPage.PropertyChanged -= OnElementPropertyChanged; } if (newPage != null) { if (_tracker == null) { _tracker = new BackgroundTracker<FlipView>(BackgroundProperty) { Control = 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(); ((IPageController)newPage).SendAppearing(); } OnElementChanged(new ElementChangedEventArgs<CarouselPage>(oldPage, newPage)); if (!string.IsNullOrEmpty(Element?.AutomationId)) SetValue(AutomationProperties.AutomationIdProperty, Element.AutomationId); }
protected virtual void Dispose(bool disposing) { if (!disposing || _disposed) return; if (_tracker != null) { _tracker.Dispose(); _tracker = null; } _disposed = true; PageController?.SendDisappearing(); SetElement(null); }
public void SetElement(VisualElement element) { if (element != null && !(element is MasterDetailPage)) throw new ArgumentException("Element must be a Page", "element"); MasterDetailPage oldElement = Element; Element = (MasterDetailPage)element; if (oldElement != null) { oldElement.PropertyChanged -= OnElementPropertyChanged; } if (element != null) { if (_container == null) { _container = new MasterDetailControl(); _container.UserClosedPopover += OnUserClosedPopover; _container.SizeChanged += OnNativeSizeChanged; Tracker = new BackgroundTracker<PageControl>(Control.BackgroundProperty) { Element = (Page)element, Container = _container }; _container.Loaded += OnLoaded; _container.Unloaded += OnUnloaded; } element.PropertyChanged += OnElementPropertyChanged; UpdateBehavior(); SetMaster(Element.Master); SetDetail(Element.Detail); UpdateIsPresented(); } OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); }
public void SetElement(VisualElement element) { if (element != null && !(element is NavigationPage)) throw new ArgumentException("Element must be a Page", "element"); NavigationPage oldElement = Element; Element = (NavigationPage)element; if (oldElement != null) { ((INavigationPageController)oldElement).PushRequested -= OnPushRequested; ((INavigationPageController)oldElement).PopRequested -= OnPopRequested; 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(); Element.PropertyChanged += OnElementPropertyChanged; ((INavigationPageController)Element).PushRequested += OnPushRequested; ((INavigationPageController)Element).PopRequested += OnPopRequested; Element.InternalChildren.CollectionChanged += OnChildrenChanged; if (!string.IsNullOrEmpty(Element.AutomationId)) _container.SetValue(AutomationProperties.AutomationIdProperty, Element.AutomationId); PushExistingNavigationStack(); } OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); }