void UpdateBottomBar() { _BottomBar.Children.Clear(); _BottomBar.ColumnDefinitions.Clear(); var items = ShellItemController?.GetItems(); if (items?.Count > 1) { for (int i = 0; i < items.Count; i++) { var section = items[i]; var btn = new AppBarButton() { Label = section.Title, Width = double.NaN, MinWidth = 68, MaxWidth = 200 }; switch (section.Icon) { case FileImageSource fileImageSource: btn.Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///" + fileImageSource.File) }; break; case FontImageSource fontImageSource: var icon = new FontIcon() { Glyph = fontImageSource.Glyph, FontFamily = new FontFamily(fontImageSource.FontFamily), FontSize = fontImageSource.Size, }; if (!fontImageSource.Color.IsDefault()) { icon.Foreground = fontImageSource.Color.ToNative(); } btn.Icon = icon; break; } btn.Click += (s, e) => OnShellSectionClicked(section); _BottomBar.ColumnDefinitions.Add(new UwpColumnDefinition() { Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star) }); SetColumn(btn, i); _BottomBar.Children.Add(btn); } } }
public static void UpdateContentLayout(this UI.Xaml.Controls.Button mauiButton, Button button) { // If the Content isn't the StackPanel setup by Maui.Core then // The user has set a custom Content or the content isn't a mix of text/images if (mauiButton.Content is not StackPanel container) { return; } var image = mauiButton.GetContent <UI.Xaml.Controls.Image>(); var textBlock = mauiButton.GetContent <UI.Xaml.Controls.TextBlock>(); // If either of these are null then the user has taken control of the content // and we don't know how to apply our changes if (image == null || textBlock == null) { return; } container.Children.Clear(); var layout = button.ContentLayout; var spacing = layout.Spacing; switch (layout.Position) { case Button.ButtonContentLayout.ImagePosition.Top: container.Orientation = Orientation.Vertical; image.Margin = WinUIHelpers.CreateThickness(0, 0, 0, spacing); container.Children.Add(image); container.Children.Add(textBlock); break; case Button.ButtonContentLayout.ImagePosition.Bottom: container.Orientation = Orientation.Vertical; image.Margin = WinUIHelpers.CreateThickness(0, spacing, 0, 0); container.Children.Add(textBlock); container.Children.Add(image); break; case Button.ButtonContentLayout.ImagePosition.Right: container.Orientation = Orientation.Horizontal; image.Margin = WinUIHelpers.CreateThickness(spacing, 0, 0, 0); container.Children.Add(textBlock); container.Children.Add(image); break; default: // Defaults to image on the left container.Orientation = Orientation.Horizontal; image.Margin = WinUIHelpers.CreateThickness(0, 0, spacing, 0); container.Children.Add(image); container.Children.Add(textBlock); break; } }
internal void UpdateHeaderInsets() { double inset = 10; if (ShellContext.IsPaneToggleButtonVisible) { inset += 45; } if (Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Microsoft.UI.Xaml.Controls.NavigationView", "IsBackButtonVisible")) { if (ShellContext.IsBackButtonVisible != Microsoft.UI.Xaml.Controls.NavigationViewBackButtonVisible.Collapsed && ShellContext.IsBackEnabled) { inset += 45; } } _HeaderArea.Padding = WinUIHelpers.CreateThickness(inset, 0, 0, 0); }
public ShellItemView(ShellView shellContext) { _ = shellContext ?? throw new ArgumentNullException(nameof(shellContext)); ShellContext = shellContext; RowDefinitions.Add(new UwpRowDefinition() { Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto) }); RowDefinitions.Add(new UwpRowDefinition() { Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star) }); RowDefinitions.Add(new UwpRowDefinition() { Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto) }); _Title = new TextBlock() { Style = Resources["SubtitleTextBlockStyle"] as UwpStyle, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis, TextWrapping = TextWrapping.NoWrap }; _HeaderArea = new UwpGrid() { Height = 40, Padding = WinUIHelpers.CreateThickness(10, 0, 10, 0) }; _HeaderArea.ColumnDefinitions.Add(new UwpColumnDefinition() { Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star) }); _HeaderArea.ColumnDefinitions.Add(new UwpColumnDefinition() { Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto) }); _HeaderArea.Children.Add(_Title); Children.Add(_HeaderArea); _Toolbar = new ItemsControl() { ItemTemplate = UwpApplication.Current.Resources["ShellToolbarItemTemplate"] as UwpDataTemplate, ItemsPanel = UwpApplication.Current.Resources["ShellToolbarItemsPanelTemplate"] as ItemsPanelTemplate, }; SetColumn(_Toolbar, 1); _HeaderArea.Children.Add(_Toolbar); SectionView = shellContext.CreateShellSectionView(); SetRow(SectionView, 1); Children.Add(SectionView); _BottomBar = new UwpGrid() { HorizontalAlignment = HorizontalAlignment.Center }; _BottomBarArea = new WBorder() { Child = _BottomBar }; SetRow(_BottomBarArea, 2); Children.Add(_BottomBarArea); }