2010-10-28 2 views
3

Here документация. Я нигде не нашел объяснений. Существует привязка данных overview, но для WPF, и я использую WinForms. Я подумал, что он должен назвать любой метод, который я назначаю событию Format класса Binding, но он вызовет его, даже если я установил formattingEnabled в значение false, пока я назначаю метод. Так что теперь я не знаю, что он делает, и я не понимаю, где люди должны получать такую ​​информацию.Что делает параметр formattingEnabled в конструкторе Binding?

ответ

-1

Похоже, что вам нужно пару штук ... Во-первых, вот бит Reflector'd на событие Format, который вы добавили

protected virtual void OnFormat(ConvertEventArgs cevent) 
{ 
    if (this.onFormat != null) 
    { 
     this.onFormat(this, cevent); 
    } 
    if (((!this.formattingEnabled && !(cevent.Value is DBNull)) && ((cevent.DesiredType != null) && !cevent.DesiredType.IsInstanceOfType(cevent.Value))) && (cevent.Value is IConvertible)) 
    { 
     cevent.Value = Convert.ChangeType(cevent.Value, cevent.DesiredType, CultureInfo.CurrentCulture); 
    } 
} 

и тогда это:

private object FormatObject(object value) 
{ 
    if (this.ControlAtDesignTime()) 
    { 
     return value; 
    } 
    Type propertyType = this.propInfo.PropertyType; 
    if (this.formattingEnabled) 
    { 
     ConvertEventArgs args = new ConvertEventArgs(value, propertyType); 
     this.OnFormat(args); 
     if (args.Value != value) 
     { 
      return args.Value; 
     } 
     TypeConverter sourceConverter = null; 
     if (this.bindToObject.FieldInfo != null) 
     { 
      sourceConverter = this.bindToObject.FieldInfo.Converter; 
     } 
     return Formatter.FormatObject(value, propertyType, sourceConverter, this.propInfoConverter, this.formatString, this.formatInfo, this.nullValue, this.dsNullValue); 
    } 
    ConvertEventArgs cevent = new ConvertEventArgs(value, propertyType); 
    this.OnFormat(cevent); 
    object obj2 = cevent.Value; 
    if (propertyType == typeof(object)) 
    { 
     return value; 
    } 
    if ((obj2 != null) && (obj2.GetType().IsSubclassOf(propertyType) || (obj2.GetType() == propertyType))) 
    { 
     return obj2; 
    } 
    TypeConverter converter2 = TypeDescriptor.GetConverter((value != null) ? value.GetType() : typeof(object)); 
    if ((converter2 != null) && converter2.CanConvertTo(propertyType)) 
    { 
     return converter2.ConvertTo(value, propertyType); 
    } 
    if (value is IConvertible) 
    { 
     obj2 = Convert.ChangeType(value, propertyType, CultureInfo.CurrentCulture); 
     if ((obj2 != null) && (obj2.GetType().IsSubclassOf(propertyType) || (obj2.GetType() == propertyType))) 
     { 
      return obj2; 
     } 
    } 
    throw new FormatException(SR.GetString("ListBindingFormatFailed")); 
} 

Поэтому он по-прежнему будет форматировать объект в соответствии с тем, что вы привязали к обработчику событий формата.

+0

: S Вы ответили на другой вопрос случайно? – Juan

+0

@jsoldi ~ Вы не используете рефлектор RedGate, не так ли? – jcolebrand

+0

Совсем нет ..... – Juan

Смежные вопросы