我们可以自定义标题栏来设置TitleBar Icon.这里的关键点是使用Window.SetTitleBar方法.以下是一个简单的示例:
首先,我们需要一个UIElement作为新的标题栏.例如,在MainPage.xaml中我们可以添加一个Grid
并在网格中,设置图标和应用程序名称.请注意,我们需要将"TitleBar" Grid
放在根网格的第一行.
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="TitleBar">
<Rectangle x:Name="BackgroundElement" Fill="Transparent" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Height="32" Margin="5,0" Source="Assets/StoreLogo.png" />
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="My Application" />
</Grid>
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
然后在MainPage.xaml.cs中,我们可以使用以下代码来设置带有图标的新标题栏.
public MainPage()
{
this.InitializeComponent();
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
// Set the BackgroundElement instead of the entire Titlebar grid
// so that we can add clickable element in title bar.
Window.Current.SetTitleBar(BackgroundElement);
}
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅GitHub上的官方标题栏示例,尤其是场景2:示例中的自定义绘图.
归档时间: |
|
查看次数: |
2074 次 |
最近记录: |