Vote count:
0
I have a generic user control, and another user control that inherits from it:
[DefaultBindingProperty("Value")]
public partial class CustomControl<T> : UserControl where T : class
{
public event ValueChangedEventHandler ValueChanged;
private T value;
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public virtual T Value
{
get { return this.value; }
set
{
OnValueChanged(new ValueChangedEventArgs(this.value, value));
this.value = value;
}
}
protected virtual void OnValueChanged(ValueChangedEventArgs e)
{
if (ValueChanged != null)
ValueChanged(this, e);
}
}
And the inherited control:
public partial class CategoryTypeControl: CategoryTypeControlParent, INotifyPropertyChanged
{
public CategoryTypeControl()
{
InitializeComponent();
}
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public override CategoryType Value
{
get { return base.Value; }
set
{
base.Value = value;
this.Text = value != null ? value.Description : string.Empty;
}
}
protected override void OnValueChanged(ValueChangedEventArgs e)
{
base.OnValueChanged(e);
OnPropertyChanged("Value");
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
[ToolboxItem(false)]
public class CategoryTypeControlParent : CustomControl<CategoryType> { }
The control is placed in a form, and the Value property is bound to a property using a binding source. The binding source is in turn bound to a POCO class.
When the user changes the Value property, the OnValueChanged method is called and in turn raises OnPropertyChanged. The event handler is not null.
However, the binding source on the form is not being updated.
What am I missing?
asked 1 min ago
WinForms User control not updating binding source
Aucun commentaire:
Enregistrer un commentaire