[英]Title bar not visible using ExtendViewIntoTitleBar=true in UWP app c#
因此,我想按照此處的建議來自定義UWP應用程序的標題欄https://docs.microsoft.com/en-gb/windows/uwp/design/shell/title-bar 。 我想使用自定義Windows.UI.Xaml.Controls.NavigationView
並顯示它,而不是默認標題欄。 所以在我的Xaml代碼中,我有:
<Page
x:Class="Posta.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Posta"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<NavigationView x:Name="TopNavigationView" Header="Hello" PaneDisplayMode="Top" IsBackButtonVisible="Collapsed" Grid.Row="0">
<NavigationView.MenuItems>
<NavigationViewItem x:Name="HomeItem" Content="Home" Icon="Home" ></NavigationViewItem>
</NavigationView.MenuItems>
</NavigationView>
<WebView Source="https://website.com" Grid.Row="1" ></WebView>
</Grid>
</Page>
在初始化頁面時,我在C#代碼中添加了代碼:
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
TopNavigationView.Height = coreTitleBar.Height; // check this height setting (because we sat it to auto in xaml)
Window.Current.SetTitleBar(TopNavigationView);
但是,現在,當我啟動應用程序時,我的NavigationView不可見,並且只有WebView擴展到了標題欄中。
您需要處理CoreApplicationViewTitleBar.LayoutMetricsChanged事件以通過coreTitleBar.Height
更新TopNavigationView.Height
,就像演示代碼中顯示的文檔一樣。
private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
{
UpdateTitleBarLayout(sender);
}
private void UpdateTitleBarLayout(CoreApplicationViewTitleBar coreTitleBar)
{
// Update title bar control size as needed to account for system size changes.
TopNavigationView.Height = coreTitleBar.Height;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.