2013-07-07 1 views
2

MahApps.Metro를 사용하는 WPF 응용 프로그램에서 창 아이콘을 설정하려고합니다. 윈도우의 XAML이 윈도우 아이콘으로 정의 된 정적 리소스를 설정하는 방법을 모르겠습니다. 다음은 정적 리소스가있는 창 아이콘 설정

는 XAML, 내가 원하는 자원이 Icons.xaml에 있습니다

<Rectangle> 
    <Rectangle.Fill> 
     <VisualBrush Visual="{StaticResource appbar_alien}" /> 
    </Rectangle.Fill> 
</Rectangle> 

어떻게 할 : 여기

<controls:MetroWindow x:Class="Test1.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="MainWindow" Height="350" Width="525" WindowState="Maximized"> 

<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.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="/Resources/Icons.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window.Resources> 

내가에 자원 에게 창을 사용하는 방법의 예입니다 appbar_alien을 창 아이콘으로 설정 하시겠습니까?

+0

Xaml의 참조가 이미 개체 그래프에 있어야합니다. 주장한 바에 의하면. (1) RD를 app.xaml로 승격시킬 수 있습니까? 또는 (2) RD를 리소스 전용 어셈블리로 옮기고 거기에서 꺼내십시오. –

답변

5

MahApps MetroWindow (Application icon stretches to title bar height when using MahApps.Metro)에서 너무 큰 아이콘에 대한 질문에 방금 대답했으며 동일한 기술을 통해 해결책을 얻을 수 있습니다.

는 기본적으로, 당신은 MetroWindow.IconTemplate 속성을 설정해야합니다 : 당신의 "/Resources/Icons.xaml"에 따라

<MahApps:MetroWindow.IconTemplate> 
    <DataTemplate> 
     <Grid Width="{TemplateBinding Width}" 
       Height="{TemplateBinding Height}" 
       Margin="4" 
       Background="Transparent" 
       RenderOptions.EdgeMode="Aliased" 
       RenderOptions.BitmapScalingMode="HighQuality"> 
       <Rectangle> 
        <Rectangle.Fill> 
         <VisualBrush Visual="{StaticResource appbar_alien}" /> 
        </Rectangle.Fill> 
       </Rectangle> 
     </Grid> 
    </DataTemplate> 
</MahApps:MetroWindow.IconTemplate> 

을, 당신은/스케일에게 그것을 스트레칭 할 수 있습니다.