2016-10-15 3 views
1

数日前にmahappsを使用していましたが(まだ学習しています)、タイトルバーにアイコンを追加しようとしましたが、Webサイトの例と同じことがすべて表示され、表示されません。MahApps RightWindowCommandにアイコンが表示されない

<Controls:MetroWindow.RightWindowCommands> 
    <Controls:WindowCommands> 
    <StackPanel Orientation="Horizontal"> 
     <Rectangle Width="20" 
       Height="20" 
       Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"> 
      <Rectangle.OpacityMask> 
       <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_cog}" /> 
      </Rectangle.OpacityMask> 
     </Rectangle> 
     <Button Margin="4 0 0 0" Content="settings" Click="Button_Click"/> 
    </StackPanel> 
    </Controls:WindowCommands> 
</Controls:MetroWindow.RightWindowCommands>` 

そして、私app.xamlを:それは私がしようとしているものだ

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" /> 
      <ResourceDictionary Source="/Resources/Icons.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

にはどうすればいいのアイコンを表示させることができますか?ここで私はそれが見えるようにしたいものの例である:What it should look like

答えて

2

試用:

MainWindow.xaml:

<Controls:MetroWindow x:Class="MahApps.Metro.Application31.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls" 
        Icon="mahapps.metro.logo2.png" 
        BorderBrush="{StaticResource AccentColorBrush}" 
        BorderThickness="2" 
        Title="MainWindow" 
        Height="350" 
        Width="350"> 

<Controls:MetroWindow.RightWindowCommands> 
    <Controls:WindowCommands> 
     <Button> 
      <StackPanel Orientation="Horizontal"> 
       <Rectangle Width="20" 
          Height="20" 
          Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"> 
        <Rectangle.OpacityMask> 
         <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_cog}" /> 
        </Rectangle.OpacityMask> 
       </Rectangle> 
       <TextBlock Margin="5,0,0,0">Settings</TextBlock> 
      </StackPanel> 
     </Button> 
    </Controls:WindowCommands> 
</Controls:MetroWindow.RightWindowCommands> 

<Grid> 
    <Rectangle Fill="{StaticResource AccentColorBrush}"> 
     <Rectangle.OpacityMask> 
      <VisualBrush Stretch="Fill" 
         Visual="{StaticResource appbar_cog}" /> 
     </Rectangle.OpacityMask> 
    </Rectangle> 
</Grid> 

App.xaml:

<Application x:Class="MahApps.Metro.Application31.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro.Resources;component/Icons.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

enter image description here


注:正しく機能するためにすべてのためにあなたがする必要があります。

1)は、明示的にプロジェクトにmahapps.metro.logo2.pngを追加します。 2)明示的にまだMahApps.Metro.Resources

enter image description here

+0

ありがとう!それはそれを解決するボタンのすべてを配置する方法、奇妙に働いた –

1

使用IconShowIconOnTitleBarShowTitleBarはあなたのコードでは、次のように:

<Controls:MetroWindow x:Class="MetroDemo.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
     Title="My Application" 
     Width="960" Height="600" 
     Icon="mahapps.metro.logo2.ico" 
     ShowIconOnTitleBar="True" 
     ShowTitleBar="True"> 
    <Grid /> 
</Controls:MetroWindow> 

編集: Demo App

+0

何:( –

+0

@ShakedDahanへのプロジェクト参照を追加し、私はあなたがMahAppsデモアプリをダウンロード(私は答えにこれを追加しました)とラインで、あなたのコードの行をチェックすることをお勧めします。 – RAM

+0

私はすでにそれをチェックしました、それは私のアプリケーションの流れの方向がRightToLeftであることができますか?それとも、あなたのアイコンファイルを正しいパスでチェックしてください。 –

関連する問題