Beispiel #1
0
        void UpdateActionBarTitle()
        {
            Page view = null;

            if (CurrentNavigationPage != null)
            {
                view = CurrentNavigationPage.CurrentPage;
            }
            else if (CurrentTabbedPage != null)
            {
                view = CurrentTabbedPage.CurrentPage;
            }

            if (view == null)
            {
                return;
            }

            ActionBar actionBar = ((Activity)_context).ActionBar;

            var useLogo   = false;
            var showHome  = false;
            var showTitle = false;

            if (ShouldShowActionBarTitleArea())
            {
                actionBar.Title = view.Title;
                FileImageSource titleIcon = NavigationPage.GetTitleIcon(view);
                if (!string.IsNullOrWhiteSpace(titleIcon))
                {
                    actionBar.SetLogo(_context.Resources.GetDrawable(titleIcon));
                    useLogo   = true;
                    showHome  = true;
                    showTitle = true;
                }
                else
                {
                    showHome  = true;
                    showTitle = true;
                }
            }

            ActionBarDisplayOptions options = 0;

            if (useLogo)
            {
                options = options | ActionBarDisplayOptions.UseLogo;
            }
            if (showHome)
            {
                options = options | ActionBarDisplayOptions.ShowHome;
            }
            if (showTitle)
            {
                options = options | ActionBarDisplayOptions.ShowTitle;
            }
            actionBar.SetDisplayOptions(options, ActionBarDisplayOptions.UseLogo | ActionBarDisplayOptions.ShowTitle | ActionBarDisplayOptions.ShowHome);

            UpdateActionBarHomeAsUp(actionBar);
        }
        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);
        }
Beispiel #3
0
        static void toggleTitleIcon(Page page)
        {
            var titleIcon = NavigationPage.GetTitleIcon(page);

            if (titleIcon == null)
            {
                NavigationPage.SetTitleIcon(page, "coffee.png");
            }
            else
            {
                NavigationPage.SetTitleIcon(page, null);
            }
        }
Beispiel #4
0
        void titleIcon_Clicked(object sender, EventArgs e)
        {
            var titleIcon = NavigationPage.GetTitleIcon(this);

            if (titleIcon == null)
            {
                NavigationPage.SetTitleIcon(this, "coffee.png");
            }
            else
            {
                NavigationPage.SetTitleIcon(this, null);
            }
        }
        public NavigationBarGallery(NavigationPage rootNavPage)
        {
            _rootNavPage = rootNavPage;

            int toggleBarTextColor       = 0;
            int toggleBarBackgroundColor = 0;

            ToolbarItems.Add(new ToolbarItem {
                Text = "Save"
            });

            NavigationPage.SetTitleIcon(this, "coffee.png");

            SearchBar searchBar = new SearchBar {
                HeightRequest = 44, WidthRequest = 100
            };

            // Note: Large and complex controls, such as ListView and TableView, are not recommended.
            var controls = new List <View>
            {
                searchBar,
                new ActivityIndicator {
                    IsRunning = true
                },
                new BoxView {
                    BackgroundColor = Color.Red
                },
                new Button {
                    Text = "Button!"
                },
                new DatePicker {
                },
                new Editor {
                    Text = "Editor"
                },
                new Entry {
                    Placeholder = "Entry"
                },
                new Image {
                    Source = "crimson.jpg", HeightRequest = 44
                },
                new Label {
                    Text = "Title View Label!"
                },
                new Picker {
                    ItemsSource = Enumerable.Range(0, 10).Select(i => $"Item {i}").ToList(), Title = "Picker"
                },
                new ProgressBar {
                    Progress = 50
                },
                new Slider {
                },
                new Stepper {
                },
                new Switch {
                },
                new TimePicker {
                }
            };

            int idx = 0;

            NavigationPage.SetTitleView(this, CreateTitleView(controls[idx]));

            rootNavPage.On <Android>().SetBarHeight(450);
            rootNavPage.On <iOS>().SetPrefersLargeTitles(false);

            Content = new ScrollView
            {
                Content =
                    new StackLayout
                {
                    Children =
                    {
                        new Button                                   {
                            Text    = "Go to SearchBarTitlePage",
                            Command = new Command(() =>              {
                                rootNavPage.PushAsync(new SearchBarTitlePage(rootNavPage));
                            })
                        },
                        new Button                                   {
                            Text    = "Change BarTextColor",
                            Command = new Command(() =>              {
                                if (toggleBarTextColor % 2 == 0)
                                {
                                    rootNavPage.BarTextColor = Color.Teal;
                                }
                                else
                                {
                                    rootNavPage.BarTextColor = Color.Default;
                                }
                                toggleBarTextColor++;
                            })
                        },
                        new Button                                   {
                            Text    = "Change BarBackgroundColor",
                            Command = new Command(() =>              {
                                if (toggleBarBackgroundColor % 2 == 0)
                                {
                                    rootNavPage.BarBackgroundColor = Color.Navy;
                                }
                                else
                                {
                                    rootNavPage.BarBackgroundColor = Color.Default;
                                }
                                toggleBarBackgroundColor++;
                            })
                        },
                        new Button                                   {
                            Text    = "Change Both to default",
                            Command = new Command(() =>              {
                                rootNavPage.BarTextColor       = Color.Default;
                                rootNavPage.BarBackgroundColor = Color.Default;
                            })
                        },
                        new Button                                   {
                            Text    = "Make sure Tint still works",
                            Command = new Command(() =>              {
        #pragma warning disable 618
                                rootNavPage.Tint = Color.Red;
        #pragma warning restore 618
                            })
                        },
                        new Button                                   {
                            Text    = "Black background, white text",
                            Command = new Command(() =>              {
                                rootNavPage.BarTextColor       = Color.White;
                                rootNavPage.BarBackgroundColor = Color.Black;
                            })
                        },
                        new Button                                   {
                            Text    = "Toggle TitleIcon",
                            Command = new Command(() =>              {
                                var titleIcon = NavigationPage.GetTitleIcon(this);

                                if (titleIcon == null)
                                {
                                    titleIcon = "coffee.png";
                                }
                                else
                                {
                                    titleIcon = null;
                                }

                                NavigationPage.SetTitleIcon(this, titleIcon);
                            })
                        },
                        new Button                                   {
                            Text    = "Toggle TitleView",
                            Command = new Command(() =>              {
                                var titleView = NavigationPage.GetTitleView(this);

                                if (titleView == null)
                                {
                                    titleView = CreateTitleView(controls[idx]);
                                }
                                else
                                {
                                    titleView = null;
                                }

                                NavigationPage.SetTitleView(this, titleView);
                            })
                        },
                        new Button                                   {
                            Text    = "Next TitleView",
                            Command = new Command(() =>              {
                                idx++;
                                if (idx >= controls.Count)
                                {
                                    idx = 0;
                                }

                                var titleView = CreateTitleView(controls[idx]);

                                NavigationPage.SetTitleView(this, titleView);
                            })
                        },
                        new Button                                   {
                            Text    = "Toggle Back Title",
                            Command = new Command(() =>              {
                                var backTitle = NavigationPage.GetBackButtonTitle(rootNavPage);

                                if (backTitle == null)
                                {
                                    backTitle = "Go back home";
                                }
                                else
                                {
                                    backTitle = null;
                                }

                                NavigationPage.SetBackButtonTitle(rootNavPage, backTitle);
                            })
                        },
                        new Button                                   {
                            Text    = "Toggle Toolbar Item",
                            Command = new Command(() =>              {
                                if (ToolbarItems.Count > 0)
                                {
                                    ToolbarItems.Clear();
                                }
                                else
                                {
                                    ToolbarItems.Add(new ToolbarItem {
                                        Text = "Save"
                                    });
                                }
                            })
                        },
                        new Button                                   {
                            Text    = "Toggle Title",
                            Command = new Command(() =>              {
                                if (Title == null)
                                {
                                    Title = "NavigationBar Gallery - Legacy";
                                }
                                else
                                {
                                    Title = null;
                                }
                            })
                        },
                        new Button                                   {
                            Text    = "Toggle BarHeight",
                            Command = new Command(() =>              {
                                if (rootNavPage.On <Android>().GetBarHeight() == -1)
                                {
                                    rootNavPage.On <Android>().SetBarHeight(450);
                                }
                                else
                                {
                                    rootNavPage.ClearValue(BarHeightProperty);
                                }
                            })
                        }
                    }
                }
            };
        }