static void UpdateToolbarPlacement(CommandBar toolbar, ToolbarPlacement toolbarPlacement, WBorder bottomCommandBarArea, WBorder topCommandBarArea, WBorder titleArea) { // Figure out what's hosting the command bar right now var current = toolbar.Parent as WBorder; // And figure out where it should be WBorder target; switch (toolbarPlacement) { case ToolbarPlacement.Top: target = topCommandBarArea; break; case ToolbarPlacement.Bottom: target = bottomCommandBarArea; break; case ToolbarPlacement.Default: default: target = Device.Idiom == TargetIdiom.Phone ? bottomCommandBarArea : topCommandBarArea; break; } if (current == null || target == null || current == target) { return; } // Remove the command bar from its current host and add it to the new one current.Child = null; target.Child = toolbar; if (titleArea != null) { if (target == bottomCommandBarArea) { // If the title is hosted in the command bar and we're moving the command bar to the bottom, // put the title into the topCommandBarArea toolbar.Content = null; topCommandBarArea.Child = titleArea; } else { // Put the title back into the command bar toolbar.Content = titleArea; } } }
public void Initialize(CommandBar commandBar, Func <ToolbarPlacement> getToolbarPlacement, Func <string, DependencyObject> getTemplateChild) { _commandBar = commandBar; _getToolbarPlacement = getToolbarPlacement; _bottomCommandBarArea = getTemplateChild("BottomCommandBarArea") as WBorder; _topCommandBarArea = getTemplateChild("TopCommandBarArea") as WBorder; _titleArea = getTemplateChild("TitleArea") as WBorder; if (_commandBar != null && _bottomCommandBarArea != null && _topCommandBarArea != null) { // We have to wait for the command bar to load so that it'll be in the control hierarchy // otherwise we can't properly move it to wherever the toolbar is supposed to be _commandBar.Loaded += (sender, args) => { UpdateToolbarPlacement(); UpdateIsInValidLocation(); }; } }
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); }
WColor GetBackgroundColor(WBorder border) { return((border.Background as WSolidColorBrush).Color); }