如何使用WPF中存储在xaml文件中的图标?

如何使用WPF中存储在xaml文件中的图标?,wpf,xaml,icons,Wpf,Xaml,Icons,对不起,我的英语不好。图标存储在名为icon.xaml的xaml文件中。我将该文件作为资源添加到项目中 <ResourceDictionary x:Class="resources_icons_xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Canvas x:K

对不起,我的英语不好。图标存储在名为icon.xaml的xaml文件中。我将该文件作为资源添加到项目中

<ResourceDictionary x:Class="resources_icons_xaml"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <Canvas x:Key="appbar_acorn" Width="48" Height="48" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0">
        <Path Width="22.3248" Height="25.8518" Canvas.Left="13.6757" Canvas.Top="11.4012" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z "/>
    </Canvas>
</ResourceDictionary >        


现在,我想使用窗口标题栏中的图标。如何执行此操作?

窗口。图标是一个
图像源。因此,您不应该在此处使用
画布。尝试将其更改为一些
DrawingImage
,如下所示:

<DrawingImage x:Key="appbar_acorn">
   <DrawingImage.Drawing>
      <GeometryDrawing Brush="{DynamicResource BlackBrush}" Geometry="F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z">
      </GeometryDrawing>
   </DrawingImage.Drawing>
</DrawingImage>
<Window ...
        Icon="{StaticResource appbar_acorn}">
    <!-- ... -->
</Window>
<Window ...
        Icon="{DynamicResource appbar_acorn}">
    <!-- ... -->
</Window>