【发布时间】:2019-03-20 12:33:55
【问题描述】:
我想更改我的图片来源:
<Image Source="{svg:SvgImage image.svg}"/>
对于在枚举属性上使用绑定的东西:
XAML:
<Resources>
<local:MyConverter x:Key="MyConverter" />
</Resources>
<Image Source="{svg:SvgImage Binding MyEnumProperty, Converter={StaticResource MyConverter}}" />
后面的代码:
public enum MyEnum
{
Value1,
Value2
}
public class MyConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var myValue = (MyEnum)(value);
switch (myValue)
{
case MyEnum.Value1:
return "image1.svg";
case MyEnum.Value2:
return "image2.svg";
default:
throw new NotImplementedException();
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
这不起作用,我怀疑这与 svg:SvgImage 和 Binding MyEnumProperty 组合在同一个语句中有关。
我收到以下错误:
The member "Converter" is not recognized or is not accessible.
和
The property 'Converter' was not found in type 'SvgImageExtension'.
问题: 这样做的正确方法是什么?
【问题讨论】:
标签: c# wpf svg binding ivalueconverter