Aus*_*ley 2 wpf xaml mahapps.metro
我试图在使用MahApps.Metro的WPF应用程序中设置窗口图标.我不知道如何在窗口的XAML之后将我定义的静态资源设置为窗口的图标.
下面是XAML,我想要的资源是Icons.xaml:
<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>
Run Code Online (Sandbox Code Playgroud)
以下是我如何在窗口上使用资源的示例:
<Rectangle>
<Rectangle.Fill>
<VisualBrush Visual="{StaticResource appbar_alien}" />
</Rectangle.Fill>
</Rectangle>
Run Code Online (Sandbox Code Playgroud)
如何设置appbar_alien窗口的图标?
我刚回答了一个关于MahApps MetroWindow中图标太大的问题(使用MahApps.Metro时应用程序图标延伸到标题栏高度),同样的技术可以为您提供解决方案.
基本上,您必须设置MetroWindow.IconTemplate属性:
<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>
Run Code Online (Sandbox Code Playgroud)
根据您的"/Resources/Icons.xaml",您可能需要拉伸/缩放它.