ast*_*tef 5 c# wpf xaml visual-studio
我有很多来自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>
Run Code Online (Sandbox Code Playgroud)
我想将其包含到我的 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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1152 次 |
| 最近记录: |