private object FindOrBindKeyValue(FrameworkElement element, DependencyProperty property) { foreach (FrameworkElement ancestor in VisualTree.EnumerateAncestors(element, true)) { FieldDefinitionContainer container = UserFieldPresenter.GetContainer(ancestor); if (container != null) { if (container.Definition != null && Key != null) { return(container.Definition.Metadata.Get(Key, default(object))); } container.Changed += () => { if (Key != null) { object value = container.Definition.Metadata.Get(Key, default(object)); element.SetValue(property, value); } }; break; } } return(null); }
private void BindToFieldDefinitionContainer() { if (isAttached) { return; } foreach (FrameworkElement ancestor in VisualTree.EnumerateAncestors(this, true)) { FieldDefinitionContainer container = GetContainer(ancestor); if (container != null) { isAttached = true; container.Changed += () => { Console.WriteLine(ancestor.Name); OnChanged(container.Definition); }; if (container.Definition != null) { OnChanged(container.Definition); } } } }
private static void SetContainerDefinition(DependencyObject d, IModelDefinition modelDefinition) { FieldDefinitionContainer container = GetContainer(d); string identifier = GetIdentifier(d); if (container != null) { if (identifier != null && modelDefinition != null) { container.Definition = modelDefinition.Fields.FirstOrDefault(f => f.Identifier == identifier); } else { container.Definition = null; } } }
public static void SetContainer(DependencyObject obj, FieldDefinitionContainer value) { obj.SetValue(ContainerProperty, value); }