2
我试图用XamlReader
在Image.Source中显示我的矢量图像。我有这样的XAML资源。WPF使用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>
创建从here的结合。
<Image Stretch="Fill" Source="{Binding Converter={StaticResource uriToUIElementConverter},ConverterParameter=images/Folder.xaml}"/>
该文件的属性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)
{
throw new NotImplementedException();
}
}
当我尝试建立项目它给了我这些错误:
System.IO.FileNotFoundException
我编辑器这样的:
Stream fileStream = Application.GetResourceStream(new Uri("pack://application:,,,/ASSEMBLYNAME;component/"+(string) parameter)).Stream;
但它不工作再次。我该怎么做才能使它工作?