使用XAML文件作为矢量图像源 [英] Using a XAML file as a vector Image Source
问题描述
我想能够使用矢量图形,$ P $在XAML pferably定义,如Image控件的来源,就像我现在可以使用光栅图像像PNG。这样,我可以很容易地混合和位图和矢量图像之间的匹配,是这样的:
I would like to be able to use vector graphics, preferably defined in XAML, as the Source of an Image control, just like I can currently use a raster image like a PNG. That way I could easily mix and match between bitmap and vector images, like this:
<StackPanel>
<Image Source="Images/Namespace.png"/>
<Image Source="Images/Module.xaml"/>
</StackPanel>
Module.xaml最有可能有&LT; DrawingImage&GT;
作为其根元素,而不是&LT;用户控件&GT;
Module.xaml would most likely have <DrawingImage>
as its root element instead of <UserControl>
.
其实,我真的去为的就是这个,所以我的视图模型可以选择自行决定光栅或矢量图像:
Actually, what I'm really going for is this, so my ViewModel could select either a raster or vector image at its discretion:
<Image Source="{Binding ImageUri}"/>
这可能吗?可以从一个给定的URI Image.Source负载XAML类?或仅是它能够加载位图资源?
Is this possible? Can Image.Source load XAML classes from a given URI? Or is it only able to load bitmap resources?
推荐答案
您可以简单地引用您的矢量图形为StaticResources:
You can simply reference your vector graphics as StaticResources:
<Image Source="{StaticResource MyImage}" />
在ResourceDictionary中作为的DrawImage的存储图像。防爆pression混合可以帮你生成这个东西:
Store the images in a ResourceDictionary as DrawImage's. Expression Blend can help you generate this stuff:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DrawingImage x:Key="MyImage">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="Black" Geometry="M 333.393,... 100.327 Z "/>
<GeometryDrawing Brush="Black" Geometry="F1 M 202.309,... Z "/>
:
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</ResourceDictionary>
这篇关于使用XAML文件作为矢量图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!