我有一个我在XAML中定义的矢量图像.在WPF应用程序中使用此资源的正确方法是什么?
我想将矢量图像放在自己的XAML文件中,然后将图像添加到我的应用程序中的其他UserControls.什么应该是我的XAML矢量图像中的顶级元素?如何在其他UserControl中引用该图像?
我在inkscape中创建了一些资源,并希望在Windows 8应用程序中将它们用作图标.我已经完成了一些阅读和接缝,而.Net 4.5支持SVG,现代的ui配置文件没有.我使用这个工具将svg转换为xaml .
我得到以下xaml.
<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="svg2997" Width="744.09448" Height="1052.3622" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Canvas x:Name="layer1">
<Path Fill="#FFCCCCCC" Stroke="#FF000000" StrokeThickness="1.34377062" StrokeMiterLimit="4" x:Name="path3007" Data="M372.58272,134.72445C167.96301,134.72445 2.06820310000001,300.58818 2.06820310000001,505.20789 2.06820310000001,709.8276 167.96301,875.72241 372.58272,875.72241 577.20243,875.72241 743.06616,709.8276 743.06616,505.20789 743.06616,300.58818 577.20243,134.72445 372.58272,134.72445z M280.73888,251.77484L455.94149,251.77484 455.94149,413.70594 628.16035,413.70594 628.16035,588.97071 455.94149,588.97071 455.94149,773.71514 280.73888,773.71514 280.73888,588.97071 106.22005,588.97071 106.22005,413.70594 280.73888,413.70594 280.73888,251.77484z" />
</Canvas>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
如果我将它直接添加到我的应用程序xaml,它将呈现但是比例是偏离的.
如果可能的话,我想将它用作图像对象的图像源.
<Image HorizontalAlignment="Left" Height="100" Margin="127,37,0,0" VerticalAlignment="Top" Width="100" Source="Assets/plus_circle.xaml"/>
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
我试图在 Image.Source 中显示我的矢量图像XamlReader。我有一个这样的 XAML 资源。
<Canvas Width="76" Height="76" ClipToBounds="True" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Path Fill="#FF000000" Height="76" Stretch="Fill" Width="76">
<Path.Data>
<PathGeometry FillRule="Nonzero" Figures="M21,30.0001L55.9999,30.0001 55.9999,50 21,50 21,30.0001z M52,28L37,28C38,25,39.4999,24.0001,39.4999,24.0001L50.75,24C51.3023,24,52,24.6977,52,25.25L52,28z" />
</Path.Data>
</Path>
Run Code Online (Sandbox Code Playgroud)
从这里创建了一个绑定。但是当我尝试使用它时它不起作用:
<Image Stretch="Fill" Source="{Binding Converter={StaticResource uriToUIElementConverter},ConverterParameter=images/Folder.xaml}"/>
Run Code Online (Sandbox Code Playgroud)
文件的属性Build Action=Resource。转换器uriTOUIElementConverter是这样的:
public class FileToUIElementConverter :IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
FileStream fileStream = new FileStream((string)parameter, FileMode.Open);
return XamlReader.Load(fileStream) as DrawingImage;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) …Run Code Online (Sandbox Code Playgroud)