void OnItemUpdated(object sender, EventArgs e) { var itemEditor = (IDataEditor <TItem>)sender; var index = ItemEditors.IndexOf(itemEditor); if (index < 0) { itemEditor.TargetUpdated -= OnItemUpdated; return; } var items = TargetNullCheck.IsNull(_editableTarget) ? default(IList <TItem>) : _propertyAdapter.GetValue(_editableTarget); if (items != null) { items[index] = itemEditor.EditableTarget; } var handler = TargetUpdated; if (handler != null) { handler(this, EventArgs.Empty); } }
public KeyValuePair <object, object> CreateElement(InitializeContext context) { object element = valueFactory.CreateElement(context); object key = null; if (keyDirectiveFactory != null) { key = keyDirectiveFactory.CreateElement(context); if (keyProperty != null) { keyProperty.SetValue(element, key, context.ValueSource); } } else if (deferredKeyFactory != null) { key = deferredKeyFactory.CreateElement(context); } else { key = keyProperty.GetValue(element); } return(new KeyValuePair <object, object>(key, element)); }
public void InitializeElement(object element, InitializeContext context) { object contentTarget = propertyAdapter.GetValue(element); if (contentTarget == null && propertyAdapter.PropertyType.GetDefaultConstructor() != null) { contentTarget = Activator.CreateInstance(propertyAdapter.PropertyType); propertyAdapter.SetValue(element, contentTarget, context.ValueSource); } propertyValueInitializer.InitializeElement(contentTarget, context); }
internal PropertyMemento(object owner, bool cascade, IPropertyAdapter prop, IMementoFactory factory) { Property = prop; Owner = Property.IsStatic ? null : owner; SavedValue = Property.GetValue(owner); Factory = factory; Children = new List <ICompositeMemento>(); if (cascade) { GenerateChildren(); } }
public void InitializeElement(object element, InitializeContext context) { context = context.CreateChildContext(element); if (!elementType.IsAssignableFrom(element.GetType())) { throw new Granular.Exception("Can't initialize element of type \"{0}\" as it's not a subclass of \"{1}\"", element.GetType().Name, elementType.Name); } if (element is ISupportInitialize) { ((ISupportInitialize)element).BeginInit(); } if (element == context.Root && element is DependencyObject) { NameScope.SetNameScope((DependencyObject)element, context.NameScope); } if (element is FrameworkElement) { ((FrameworkElement)element).TemplatedParent = context.TemplatedParent; } foreach (IElementInitializer memberInitializer in memberInitializers) { memberInitializer.InitializeElement(element, context); } string name = nameDirectiveValue.DefaultIfNullOrEmpty(nameProperty != null ? (string)nameProperty.GetValue(element) : String.Empty); if (!nameDirectiveValue.IsNullOrEmpty() && nameProperty != null) { // name property exists, but the name directive was used, so update the property nameProperty.SetValue(element, name, context.ValueSource); } if (!name.IsNullOrEmpty()) { context.NameScope.RegisterName(name, element); } if (contentInitializer != null) { contentInitializer.InitializeElement(element, context); } if (element == context.Root) { foreach (KeyValuePair <string, object> pair in context.NameScope) { SetFieldValue(element, pair.Key, pair.Value); } } if (element is ISupportInitialize) { ((ISupportInitialize)element).EndInit(); } }
public KeyValuePair <object, object> CreateElement(InitializeContext context) { object element = valueFactory.CreateElement(context); object key = keyDirectiveFactory != null?keyDirectiveFactory.CreateElement(context) : keyProperty.GetValue(element); if (keyDirectiveFactory != null && keyProperty != null) { // key property exists, but the key directive was used, so update the property keyProperty.SetValue(element, key, context.ValueSource); } return(new KeyValuePair <object, object>(key, element)); }