private void SetupBackButton() { var children = XamlUtilities.RecurseChildren(ShellView); var grids = children.OfType <Grid>(); var grid = grids.Single(x => x.Name == "TogglePaneTopPadding"); grid.Visibility = Visibility.Collapsed; grid = grids.Single(x => x.Name == "ContentPaneTopPadding"); grid.RegisterPropertyChangedCallback(HeightProperty, (s, args) => { if (grid.Height != 44d) { grid.Height = 44d; } }); grid.Height = 44d; var buttons = children.OfType <Button>(); var button = buttons.Single(x => x.Name == "TogglePaneButton"); button.RegisterPropertyChangedCallback(MarginProperty, (s, args) => { if (button.Margin.Top != 0) { button.Margin = new Thickness(0, 0, 0, 32); } }); button.Margin = new Thickness(0, 0, 0, 32); button.Focus(FocusState.Programmatic); var parent = button.Parent as Grid; var backButton = new Button { Name = "BackButton", Content = new SymbolIcon { Symbol = Symbol.Back, IsHitTestVisible = false }, Style = Resources["PaneToggleButtonStyle"] as Style, }; parent.Children.Insert(1, backButton); ShellView.NavigationService.CanGoBackChanged += (s, args) => { backButton.IsEnabled = ShellView.NavigationService.CanGoBack(); }; backButton.Click += (s, args) => { _gestureService.RaiseBackRequested(); }; }
private void SetupBackButton() { var children = XamlUtilities.RecurseChildren(this); var grids = children.OfType <Grid>(); var grid = grids.Single(x => x.Name == "TogglePaneTopPadding"); grid.Visibility = Visibility.Collapsed; grid = grids.Single(x => x.Name == "ContentPaneTopPadding"); grid.RegisterPropertyChangedCallback(HeightProperty, (s, args) => { if (grid.Height != 44d) { grid.Height = 44d; } }); grid.Height = 44d; var child_buttons = children.OfType <Button>(); _togglePaneButton = child_buttons.Single(x => x.Name == "TogglePaneButton"); _togglePaneButton.RegisterPropertyChangedCallback(MarginProperty, (s, args) => { if (_togglePaneButton.Margin.Top != 0) { _togglePaneButton.Margin = new Thickness(0, 0, 0, 32); } }); _togglePaneButton.Margin = new Thickness(0, 0, 0, 32); _togglePaneButton.Focus(FocusState.Programmatic); var parent_grid = _togglePaneButton.Parent as Grid; parent_grid.Width = double.NaN; parent_grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(48) }); parent_grid.ColumnDefinitions.Add(new ColumnDefinition { }); parent_grid.RowDefinitions[0].Height = GridLength.Auto; parent_grid.RowDefinitions[1].Height = GridLength.Auto; _paneTitleTextBlock = new TextBlock { Name = "PaneTitleTextBlock", Margin = new Thickness(8, 18, 0, 0), FontSize = 15, FontFamily = new FontFamily("Segoe UI Bold"), TextWrapping = TextWrapping.NoWrap, Foreground = Resources["SystemControlForegroundBaseHighBrush"] as Brush, VerticalAlignment = VerticalAlignment.Top, IsHitTestVisible = false, Text = "Jerry Nixon", }; _paneTitleTextBlock.SetValue(Grid.ColumnProperty, 1); _paneTitleTextBlock.SetValue(Grid.RowProperty, 1); _paneTitleTextBlock.SetValue(Canvas.ZIndexProperty, 100); // parent_grid.Children.Add(_paneTitleTextBlock); _backButton = new Button { Name = "BackButton", Content = new SymbolIcon { Symbol = Symbol.Back, IsHitTestVisible = false }, Style = Resources["PaneToggleButtonStyle"] as Style, }; _backButton.SetValue(Canvas.ZIndexProperty, 100); parent_grid.Children.Insert(1, _backButton); NavigationService.CanGoBackChanged += (s, args) => { _backButton.IsEnabled = NavigationService.CanGoBack(); }; _backButton.Click += (s, args) => { var gesture_service = GestureService.GetForCurrentView(); gesture_service.RaiseBackRequested(); }; }
private void UpdatePageHeaderContent() { _updatePageHeaderSemaphore.Wait(); try { if (_frame.Content is Page page) { if (page.GetValue(NavProperties.HeaderProperty) is string headerText && !Equals(Header, headerText)) { Header = headerText; } if (!(page.GetValue(NavProperties.HeaderCommandsProperty) is ObservableCollection <object> headerCommands) || !(headerCommands.Any())) { localClearPageHeaderCommands(); } else { localUpdatePageHeaderCommands(headerCommands); } } } finally { _updatePageHeaderSemaphore.Release(); } #region local functions void localClearPageHeaderCommands() { if (!localTryGetCommandBar(out var bar)) { return; } bar.PrimaryCommands.Clear(); } bool localTryGetCommandBar(out CommandBar bar) { var children = XamlUtilities.RecurseChildren(this); var bars = children .OfType <CommandBar>(); if (!bars.Any()) { bar = default(CommandBar); return(false); } bar = bars.First(); return(true); } void localUpdatePageHeaderCommands(ObservableCollection <object> headerCommands) { if (!localTryGetCommandBar(out var bar)) { return; } var previous = bar.PrimaryCommands .OfType <DependencyObject>() .Where(x => x.GetValue(NavProperties.PageHeaderCommandDynamicItemProperty) is bool value && value); foreach (var command in previous.OfType <ICommandBarElement>().ToArray()) { bar.PrimaryCommands.Remove(command); } foreach (var command in headerCommands.Reverse().OfType <DependencyObject>().ToArray()) { command.SetValue(NavProperties.PageHeaderCommandDynamicItemProperty, true); bar.PrimaryCommands.Insert(0, command as ICommandBarElement); } } #endregion }