public ToolbarItems() { var label = new Label { Text = "Hello ContentPage", AutomationId = "label_id" }; var command = new Command((obj) => { label.Text = "button 4 new text"; }, (obj) => _isEnable); var tb1 = new ToolbarItem("tb1", "menuIcon.png", () => { label.Text = "tb1"; }, ToolbarItemOrder.Primary); tb1.IsEnabled = _isEnable; tb1.AutomationId = "toolbaritem_primary"; var fis = new FontImageSource() { FontFamily = GetFontFamily(), Glyph = '\uf101'.ToString(), Color = Color.Red }; var tb2 = new ToolbarItem("tb2 font", null, () => { label.Text = "tb2"; }, ToolbarItemOrder.Primary); tb2.IconImageSource = fis; tb2.AutomationId = "toolbaritem_primary2"; var tb6 = new ToolbarItem("tb6 long long text", null, () => { label.Text = "tb6"; }, ToolbarItemOrder.Primary); tb6.AutomationId = "toolbaritem_primary6"; var tb3 = new ToolbarItem("tb3", "bank.png", () => { label.Text = "tb3"; _isEnable = !_isEnable; command.ChangeCanExecute(); }, ToolbarItemOrder.Secondary); tb3.AutomationId = "toolbaritem_secondary"; var tb4 = new ToolbarItem(); tb4.Text = "tb4"; tb4.Order = ToolbarItemOrder.Secondary; tb4.Command = command; tb4.IconImageSource = "coffee"; tb4.AutomationId = "toolbaritem_secondary2"; var tb5 = new ToolbarItem(); tb5.Text = "tb5"; tb5.IconImageSource = "bank.png"; tb5.Order = ToolbarItemOrder.Secondary; tb5.Command = new Command(async() => { await Navigation.PushAsync(new ToolbarItems()); }); tb5.AutomationId = "toolbaritem_secondary5"; ToolbarItems.Add(tb1); ToolbarItems.Add(tb2); ToolbarItems.Add(tb3); ToolbarItems.Add(tb4); ToolbarItems.Add(tb5); ToolbarItems.Add(tb6); Content = new StackLayout { Children = { label } }; }
public FontImageSourceGallery() { var grid = new Grid { HeightRequest = 1696, WidthRequest = 320, BackgroundColor = Color.Black }; grid.AddRowDef(count: 53); grid.AddColumnDef(count: 10); var fontFamily = ""; switch (Device.RuntimePlatform) { case Device.macOS: case Device.iOS: fontFamily = "Ionicons"; break; case Device.UWP: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.WPF: case Device.GTK: fontFamily = "Assets/ionicons.ttf#ionicons"; break; case Device.Android: default: fontFamily = "fonts/ionicons.ttf#"; break; } grid.Children.Add(new ImageButton { Source = new FontImageSource { Glyph = Ionicons[Ionicons.Length - 1].ToString(), FontFamily = fontFamily, Size = 20 }, }); var i = 1; foreach (char c in Ionicons) { grid.Children.Add(new Image { Source = new FontImageSource { Glyph = c.ToString(), FontFamily = fontFamily, Size = 20 }, BackgroundColor = Color.Black, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, }, i % 10, i / 10); i++; } Content = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Content = grid }; var tb1 = new ToolbarItem() { Text = "tb1", IconImageSource = new FontImageSource() { FontFamily = fontFamily, Glyph = '\uf101'.ToString() } }; var tb2 = new ToolbarItem { Text = "tb2 red", IconImageSource = new FontImageSource() { FontFamily = fontFamily, Glyph = '\uf101'.ToString(), Color = Color.Red }, }; var tb3 = new ToolbarItem { Text = "tb3 yellow", IconImageSource = new FontImageSource() { FontFamily = fontFamily, Glyph = '\uf2c7'.ToString(), Color = Color.Yellow }, }; ToolbarItems.Add(tb1); ToolbarItems.Add(tb2); ToolbarItems.Add(tb3); }
public NavigationBarGallery(NavigationPage rootNavPage) { _rootNavPage = rootNavPage; int toggleBarTextColor = 0; int toggleBarBackgroundColor = 0; ToolbarItems.Add(new ToolbarItem { Text = "Save" }); NavigationPage.SetTitleIconImageSource(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 = "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.GetTitleIconImageSource(this); if (titleIcon == null) { titleIcon = "coffee.png"; } else { titleIcon = null; } NavigationPage.SetTitleIconImageSource(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); } }) } } } }; }