我正在尝试使用IFormatProvider来自定义一些数据绑定;但是IFormatProvider类从未被调用过。我在自定义格式化类中将断点放在这两个函数的开头,并且都没有通过数据绑定进行命中。当我在String.Format中使用我的自定义格式化类时,它可以工作。
我使用的是WinForm2.0和.Net。
这就是我做数据绑定的方法:
label1.DataBindings.Add("Text", textBox1, "Text", true,
DataSourceUpdateMode.OnPropertyChanged,
"<NULL>","{0:H}",new MyFormat());我是这样使用String.Format的:
string test =(string.Format(_superFormat, "{0}", "this is my arg"));这是我的自定义格式化类:
class MyFormat : IFormatProvider, ICustomFormatter
{
string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider)
{
string result = ((string)arg).ToUpper();
return result ;
}
object IFormatProvider.GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
return this;
else
return null;
}
}https://stackoverflow.com/questions/786903
复制相似问题