【发布时间】:2022-01-20 09:13:44
【问题描述】:
我已经下载了包含 XAML 图标的 Visual Studio Image Library。例如这是FolderClosed_16x.xaml文件的内容:
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M0,0L16,0 16,16 0,16z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M1.5,1L9.61,1 10.61,3 13.496,3C14.323,3,14.996,3.673,14.996,4.5L14.996,12.5C14.996,13.327,14.323,14,13.496,14L1.5,14C0.673,14,0,13.327,0,12.5L0,2.5C0,1.673,0.673,1,1.5,1" />
<GeometryDrawing Brush="#FFEFEFF0" Geometry="F1M1.9998,3.0004L1.9998,4.0004 8.8738,4.0004 8.3738,3.0004z" />
<GeometryDrawing Brush="#FFDBB679" Geometry="F1M2,3L8.374,3 8.874,4 2,4z M13.496,4L10,4 9.992,4 8.992,2 1.5,2C1.225,2,1,2.224,1,2.5L1,12.5C1,12.776,1.225,13,1.5,13L13.496,13C13.773,13,13.996,12.776,13.996,12.5L13.996,4.5C13.996,4.224,13.773,4,13.496,4" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>
我已将此文件添加到我在 Visual Studio 中的项目中。如何在另一个 XAML 文件中使用该图标?将这些行粘贴到我的 XAML 文件中可以按预期工作,但我想将所有图标文件保存在一个目录中并在多个位置引用它们。不修改图标文件可以吗?
我想在我的MainWindow.xaml 中这样使用它,但这不起作用:
<ContentControl Template="{StaticResource Icons/FolderClosed_16x.xaml}" />
【问题讨论】:
-
你必须将它添加到资源字典并给它一个 x:Key 然后你可以将它添加到 contentControl 的内容中。例如。 x:Key="MyViewBox"
docs.microsoft.com/en-us/windows/apps/design/style/… -
@NawedNabiZada 你能举一个引用 xaml 文件的资源字典的例子吗?您提供的链接没有这样的例子。还是我理解错了?
-
资源字典是一个 xaml 文件。但是您可以加载的文件实际上并不是项目的一部分,也不是在运行时编译到其中的。 Microsoft 对他们的 technet 库进行了分箱,因此链接的示例将不起作用,但这描述了一种在运行时从磁盘加载未编译的 xaml 文件的方法。 social.technet.microsoft.com/wiki/contents/articles/…