Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TitleView work in NavigationPage and Shell on Windows #5293

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,14 @@
</ReturnValue>
<Docs>
<summary>Backing store for the attached property that gets and sets title views.</summary>
<remarks>To be added.</remarks>
<remarks>On Windows, the TitleView will appear in the content area of the MauiToolbar control. By default, the content area's width is auto-sized to the content, with the remaining area made available for toolbar commands. This is to support the default Windows-specific dynamic overflow ability of the commands. If a user wants the TitleView to occupy all of the space not used by toolbar commands, dynamic overflow needs to be turned off, which can be accomplished by calling the Page's SetToolbarDynamicOverflowEnabled PlatformSpecific to false:

<example>
<code>this.On&lt;WindowsOS&gt;().SetToolbarDynamicOverflowEnabled(false);</code>
</example>

</remarks>

</Docs>
</Member>
<Member MemberName="Microsoft.Maui.Controls.INavigationPageController.RemoveAsyncInner">
Expand Down
17 changes: 16 additions & 1 deletion src/Controls/src/Core/NavigationPageToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEvent
Color GetBarTextColor() => _currentNavigationPage?.BarTextColor;
Color GetIconColor() => (_currentPage != null) ? NavigationPage.GetIconColor(_currentPage) : null;
string GetTitle() => _currentPage?.Title;
VisualElement GetTitleView() => (_currentNavigationPage != null) ? NavigationPage.GetTitleView(_currentNavigationPage) : null;
VisualElement GetTitleView()
{
if (_currentNavigationPage == null)
{
return null;
}

Page target = _currentNavigationPage;

if (_currentNavigationPage.CurrentPage is Page currentPage)
{
target = currentPage;
}

return NavigationPage.GetTitleView(target);
}
}
}
3 changes: 2 additions & 1 deletion src/Core/src/Platform/Windows/MauiToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<TextBlock VerticalAlignment="Center" x:Name="title" TextWrapping="NoWrap" Margin="10,0,0,0"/>
</Border>

<ContentControl x:Name="titleView" Grid.Column="3" HorizontalAlignment="Stretch" />
<ContentControl x:Name="titleView" Grid.Column="3" HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />

</Grid>
</CommandBar.Content>
Expand Down