1
简单问题:.NET WPF的IValueConverter构造
为什么我必须有一个IValueConverter
一个constructor
?
我不是问,为什么我必须有一个empty constructor
,我问我为什么必须有一个?
如果我有:
public class PauseButtonValueConverter : MarkupExtension, IValueConverter
{
//public PauseButtonValueConverter() //<- Uncomment this and the error is fixed
//{
//}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
然后,我VS2012
给我的编译时错误:No constructor for type 'PauseButtonValueConverter' has 0 parameters.
如果我添加了constructor
,错误是固定的。
@ MichaelGunter-这是有道理的......我没有考虑到这个事实,即默认的构造函数不会被生成,因为我的基类。 – Andrew