/// <summary> /// When overridden in a derived class, sets the value of the component to a different value. /// </summary> public override void SetValue(object component, object value) { var stringValue = value as string; var settingsValue = value as IPropertyBindingSettings; // The setter will be called with a plain string value whenever the standard values editor is // used to pick the TypeId. So we need to actually set that value on the binding instead. if (stringValue != null) { // Note that the setting of the property Value automatically triggers a property changed // that will cause the value to be serialized and saved :). Indeed, // it will be calling the SetValue again, but this time with the entire binding settings // so it will call the next code branch. ((IPropertyBindingSettings)this.GetValue(component)).Value = stringValue; } else if (settingsValue != null) { // Someone is explicitly setting the entire binding value, so we have to serialize it straight. base.SetValue(component, BindingSerializer.Serialize(settingsValue)); // If the previous value was non-null, then we'd be monitoring its property changes // already, and we'd need to unsubscribe. if (this.settings != null) { this.settings.PropertyChanged -= OnSettingsChanged; } // Store for reuse on GetValue, and attach to property changes for auto-save. this.settings = settingsValue; this.settings.PropertyChanged += OnSettingsChanged; } }
private void SaveSettings() { if (!this.settings.IsConfigured()) { this.setValue(BindingSettings.Empty); } else { this.setValue(BindingSerializer.Serialize(this.settings)); } }
private void SaveSettings(object component, BindingSettings settings) { if (!this.settings.IsConfigured()) { base.SetValue(component, BindingSettings.Empty); } else { base.SetValue(component, BindingSerializer.Serialize(settings)); } }
private IPropertyBindingSettings CreateSettings() { IPropertyBindingSettings settings; if (string.IsNullOrEmpty(getValue())) { settings = new PropertyBindingSettings { Name = this.propertyName, Value = BindingSettings.Empty, ValueProvider = null, }; } else { // Be backwards compatible to ease migration. try { settings = BindingSerializer.Deserialize <PropertyBindingSettings>(getValue()); } catch (BindingSerializationException) { // This would happen if the value was a raw value from before we had a binding. // Consider it the property value. settings = new PropertyBindingSettings { Name = this.propertyName, Value = this.getValue(), }; // Persist updated value. this.setValue(BindingSerializer.Serialize(settings)); } } // Automatically serialize whenever something is changed in the binding. settings.PropertyChanged += OnSettingsChanged; return(settings); }