2016-07-13 5 views
7

UWPでTitleBar(ウィンドウ)にアイコンを設定する方法は?タイトルバーアイコンのUWPでTitleBarアイコンを設定する方法は?

例:

+0

これを確認してください。http://www.codezero.one/Details?d=1507&a=9&f=191&l=0&v=d&t=Win10-Sample:Title-bar-sample –

答えて

9

我々はタイトルバーアイコンを設定するには、タイトルバーをカスタマイズすることができます。ここでのポイントはWindow.SetTitleBar methodです。以下は簡単なサンプルです:

まず、新しいタイトルバーとしてUIElementが必要です。たとえば、MainPage.xamlGridを追加し、グリッドにアイコンとアプリケーション名を設定します。 「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); 
} 

は、詳細情報については、あなたは特にシナリオ2は、GitHubの上の公式Title bar sampleを参照することができます。

関連する問題