2016-07-13 2 views

ответ

9

Мы можем настроить строку заголовка, чтобы настроить Titlebar значок. Ключевым моментом здесь является использование Window.SetTitleBar method. Ниже приведен простой пример:

Во-первых, нам нужна 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> 

Тогда в 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); 
} 

Для получения дополнительной информации, Вы можете обратиться к официальному Title bar sample на GitHub, особенно сценарий 2: Пользовательский рисунок в образце.

Смежные вопросы