Running my ContentPage
in WinUI, which is wrapped with a NavigationPage
at runtime, needs a custom TitleView
I've put the same content in both TitleView and Content sections:
<NavigationPage.TitleView>
<Grid VerticalOptions="FillAndExpand" BackgroundColor="CornflowerBlue">
<Label Text="Center me!" Style="{StaticResource H1}" TextColor="White" HorizontalOptions="Center"/>
</Grid>
</NavigationPage.TitleView>
<ContentPage.Content>
<Grid VerticalOptions="FillAndExpand" BackgroundColor="CornflowerBlue">
<Label Text="Center me!" Style="{StaticResource H1}" TextColor="White" HorizontalOptions="Center"/>
</Grid>
</ContentPage.Content>
The title won't center like the ContentPage.Content
or like Xamarin does. No matter what I've tried, <Grid>
, <HoritonalStackLayout>
and every HorizontalOptions
the content is always pinned on left and sized exactly fit the text, instead of expanding the <Grid>
or <StackLayout
> to the window width (WinUI) and centering its children.
The only thing it seems to respond to is WidthRequest
but that isn't very useful.