Index: src/Common/DelftTools.Controls.Swf/DataEditorGenerator/Binding/Binding.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/DelftTools.Controls.Swf/DataEditorGenerator/Binding/Binding.cs (.../Binding.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/DelftTools.Controls.Swf/DataEditorGenerator/Binding/Binding.cs (.../Binding.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -6,26 +6,38 @@ { internal abstract class Binding : IBinding where TControl : Control { - private static ErrorProvider errorProvider = new ErrorProvider {BlinkStyle = ErrorBlinkStyle.NeverBlink}; + private static readonly ErrorProvider errorProvider = new ErrorProvider + { + BlinkStyle = ErrorBlinkStyle.NeverBlink + }; protected FieldUIDescription FieldDescription; protected TControl Control; protected Control ParentControl; private object data; - Control IBinding.EditControl { get { return Control; } } - FieldUIDescription IBinding.FieldDescription { get { return FieldDescription; } } + Control IBinding.EditControl + { + get + { + return Control; + } + } - public void InitializeControl(FieldUIDescription fieldDescription, Control editControl, Control parentControl) + FieldUIDescription IBinding.FieldDescription { - FieldDescription = fieldDescription; - Control = (TControl)editControl; - ParentControl = parentControl; + get + { + return FieldDescription; + } } - + public object Data { - get { return data; } + get + { + return data; + } set { if (data != null) @@ -44,22 +56,25 @@ } } - protected object DataValue + public void InitializeControl(FieldUIDescription fieldDescription, Control editControl, Control parentControl) { - get { return FieldDescription.GetValue(Data); } - set { CommitValue(value); } + FieldDescription = fieldDescription; + Control = (TControl) editControl; + ParentControl = parentControl; } public void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (Control.InvokeRequired) + { return; //not important enough to Invoke for + } //maybe lazy only? refresh validation status if we currently have an error // if (!string.IsNullOrEmpty(errorProvider.GetError(Control))) Validate(GetControlValue()); - + //general filtering if (FieldDescription.AlwaysRefresh || FieldDescription.HasDependencyFunctions || FieldDescription.Name == e.PropertyName) { @@ -71,12 +86,41 @@ public void RefreshEnabled() { if (Control.InvokeRequired) + { return; //not important enough to Invoke for + } ParentControl.Visible = FieldDescription.IsVisible(data); ParentControl.Enabled = FieldDescription.IsEnabled(Data); } + public void Validate(object value) + { + errorProvider.SetIconAlignment(Control, ErrorIconAlignment.MiddleLeft); + string errorMessage; + if (!FieldDescription.Validate(Data, value, out errorMessage)) + { + errorProvider.SetError(Control, errorMessage); + } + + else + { + errorProvider.SetError(Control, string.Empty); + } + } + + protected object DataValue + { + get + { + return FieldDescription.GetValue(Data); + } + set + { + CommitValue(value); + } + } + protected void CommitValue(object value) { Validate(value); @@ -85,20 +129,11 @@ //set in datasource if changed var currentValue = FieldDescription.GetValue(Data); if (!Equals(currentValue, value)) + { FieldDescription.SetValue(Data, value); + } } - public void Validate(object value) - { - errorProvider.SetIconAlignment(Control, ErrorIconAlignment.MiddleLeft); - string errorMessage; - if (!FieldDescription.Validate(Data, value, out errorMessage)) - errorProvider.SetError(Control, errorMessage); - - else - errorProvider.SetError(Control, string.Empty); - } - protected abstract object GetControlValue(); protected abstract void Initialize();