gpt4 book ai didi

c# - 如何包含不是资源的原始 xaml 文件?

转载 作者:行者123 更新时间:2023-12-04 13:46:05 28 4
gpt4 key购买 nike

我有很多来自 Visual Studio Image Library 的 XAML 文件.这是其中之一的内容 - Add_16xMD.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="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M10,7L14,7 14,10 10,10 10,14 7,14 7,10 3,10 3,7 7,7 7,3 10,3z" />
<GeometryDrawing Brush="#FF388A34" Geometry="F1M13,8L9,8 9,4 8,4 8,8 4,8 4,9 8,9 8,13 9,13 9,9 13,9z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>

我想将它包含到我的 WPF 项目中并在我的应用程序中使用。我不想复制粘贴代码,也不想修改这些用 ResourceDictionary 包装它们的文件.

有什么办法可以实现吗?

最佳答案

只需将它们作为简单的文件资源包含在您的应用程序中即可。然后你可以简单地通过 XamlReader 传递它们实例,它将为您提供根项目的实例(在本例中为 ViewBox)。从那里开始,随心所欲。

https://blogs.msdn.microsoft.com/ashish/2007/08/14/dynamically-loading-xaml

简而言之,这样做...

StreamReader mysr = new StreamReader("SomeFile.xaml");
ViewBox myLoadedViewBox = XamlReader.Load(mysr.BaseStream) as ViewBox;

关于c# - 如何包含不是资源的原始 xaml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48129548/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com