async void setTitleImage(ParentingViewController pack, FileImageSource titleIcon) { var source = Internals.Registrar.Registered.GetHandler <IImageSourceHandler>(titleIcon.GetType()); var image = await source.LoadImageAsync(titleIcon); //UIImage ctor throws on file not found if MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure is true; pack.NavigationItem.TitleView = new UIImageView(image); }
ParentingViewController CreateViewControllerForPage(Page page) { if (Platform.GetRenderer(page) == null) { Platform.SetRenderer(page, Platform.CreateRenderer(page)); } // must pack into container so padding can work // otherwise the view controller is forced to 0,0 var pack = new ParentingViewController(this) { Child = page }; if (!string.IsNullOrWhiteSpace(page.Title)) { pack.NavigationItem.Title = page.Title; } // First page and we have a master detail to contend with UpdateLeftBarButtonItem(pack); //var pack = Platform.GetRenderer (view).ViewController; var titleIcon = NavigationPage.GetTitleIcon(page); if (!string.IsNullOrEmpty(titleIcon)) { try { //UIImage ctor throws on file not found if MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure is true; pack.NavigationItem.TitleView = new UIImageView(new UIImage(titleIcon)); } catch { } } var titleText = NavigationPage.GetBackButtonTitle(page); if (titleText != null) { // adding a custom event handler to UIBarButtonItem for navigating back seems to be ignored. pack.NavigationItem.BackBarButtonItem = new UIBarButtonItem { Title = titleText, Style = UIBarButtonItemStyle.Plain }; } var pageRenderer = Platform.GetRenderer(page); pack.View.AddSubview(pageRenderer.ViewController.View); pack.AddChildViewController(pageRenderer.ViewController); pageRenderer.ViewController.DidMoveToParentViewController(pack); return(pack); }
void UpdateLeftBarButtonItem(ParentingViewController containerController, Page pageBeingRemoved = null) { if (containerController == null) { return; } var currentChild = containerController.Child; var firstPage = ((NavigationPage)Element).Pages.FirstOrDefault(); if ((firstPage != pageBeingRemoved && currentChild != firstPage && NavigationPage.GetHasBackButton(currentChild)) || _parentMasterDetailPage == null) { return; } SetMasterLeftBarButton(containerController, _parentMasterDetailPage); }
ParentingViewController CreateViewControllerForPage(Page page) { if (Platform.GetRenderer(page) == null) Platform.SetRenderer(page, Platform.CreateRenderer(page)); // must pack into container so padding can work // otherwise the view controller is forced to 0,0 var pack = new ParentingViewController(this) { Child = page }; pack.UpdateTitleArea(page); var pageRenderer = Platform.GetRenderer(page); pack.View.AddSubview(pageRenderer.ViewController.View); pack.AddChildViewController(pageRenderer.ViewController); pageRenderer.ViewController.DidMoveToParentViewController(pack); return pack; }
void UpdateLeftBarButtonItem(ParentingViewController containerController, Page pageBeingRemoved = null) { if (containerController == null) { return; } var currentChild = containerController.Child; var firstPage = ((INavigationPageController)Element).Pages.FirstOrDefault(); if ((firstPage != pageBeingRemoved && currentChild != firstPage && NavigationPage.GetHasBackButton(currentChild)) || _parentMasterDetailPage == null) { return; } if (!_parentMasterDetailPage.ShouldShowToolbarButton()) { containerController.NavigationItem.LeftBarButtonItem = null; return; } var shouldUseIcon = _parentMasterDetailPage.Master.Icon != null; if (shouldUseIcon) { try { containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(new UIImage(_parentMasterDetailPage.Master.Icon), UIBarButtonItemStyle.Plain, (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented); } catch (Exception) { // Throws Exception otherwise would catch more specific exception type shouldUseIcon = false; } } if (!shouldUseIcon) { containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(_parentMasterDetailPage.Master.Title, UIBarButtonItemStyle.Plain, (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented); } }
void UpdateLeftBarButtonItem(ParentingViewController containerController, Page pageBeingRemoved = null) { if (containerController == null) return; var currentChild = containerController.Child; var firstPage = ((INavigationPageController)Element).StackCopy.LastOrDefault(); if ((firstPage != pageBeingRemoved && currentChild != firstPage && NavigationPage.GetHasBackButton(currentChild)) || _parentMasterDetailPage == null) return; if (!_parentMasterDetailPage.ShouldShowToolbarButton()) { containerController.NavigationItem.LeftBarButtonItem = null; return; } var shouldUseIcon = _parentMasterDetailPage.Master.Icon != null; if (shouldUseIcon) { try { containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(new UIImage(_parentMasterDetailPage.Master.Icon), UIBarButtonItemStyle.Plain, (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented); } catch (Exception) { // Throws Exception otherwise would catch more specific exception type shouldUseIcon = false; } } if (!shouldUseIcon) { containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(_parentMasterDetailPage.Master.Title, UIBarButtonItemStyle.Plain, (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented); } }
ParentingViewController CreateViewControllerForPage(Page page) { if (Platform.GetRenderer(page) == null) Platform.SetRenderer(page, Platform.CreateRenderer(page)); // must pack into container so padding can work // otherwise the view controller is forced to 0,0 var pack = new ParentingViewController(this) { Child = page }; if (!string.IsNullOrWhiteSpace(page.Title)) pack.NavigationItem.Title = page.Title; // First page and we have a master detail to contend with UpdateLeftBarButtonItem(pack); //var pack = Platform.GetRenderer (view).ViewController; var titleIcon = NavigationPage.GetTitleIcon(page); if (!string.IsNullOrEmpty(titleIcon)) { try { //UIImage ctor throws on file not found if MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure is true; pack.NavigationItem.TitleView = new UIImageView(new UIImage(titleIcon)); } catch { } } var titleText = NavigationPage.GetBackButtonTitle(page); if (titleText != null) { pack.NavigationItem.BackBarButtonItem = new UIBarButtonItem(titleText, UIBarButtonItemStyle.Plain, async (o, e) => await PopViewAsync(page)); } var pageRenderer = Platform.GetRenderer(page); pack.View.AddSubview(pageRenderer.ViewController.View); pack.AddChildViewController(pageRenderer.ViewController); pageRenderer.ViewController.DidMoveToParentViewController(pack); return pack; }