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 void TryRegisterSelf() { if (!isAdded) { FieldValueProviderCollection collection = VisualTree.FindFieldValueProviderCollection(this); if (collection != null) { collection.Add(Definition.Identifier, this); isAdded = true; } } }
private static void BindModelContainerChanged(DependencyObject d) { foreach (FrameworkElement ancestor in VisualTree.EnumerateAncestors((FrameworkElement)d)) { ModelDefinitionContainer container = UserModelPresenter.GetContainer(ancestor); if (container != null) { SetContainerDefinition(d, container.Definition); container.Changed += () => SetContainerDefinition(d, container.Definition); break; } } }
private void OnChanged(IFieldDefinition definition) { TryDisposeFieldView(); Definition = definition; TryRegisterSelf(); if (VisualTree.TryGetFieldViewProvider(this, out IFieldViewProvider <IRenderContext> viewProvider) && VisualTree.TryGetModelDefinition(this, out IModelDefinition modelDefinition)) { View = viewProvider.Get(modelDefinition, definition); View.Render(new ContentControlRenderContext(this)); } }
private void OnChanged() { TryDisposeModelView(); if (Definition == null) { return; } if (VisualTree.TryGetModelViewProvider(this, out IModelViewProvider <IRenderContext> viewProvider)) { View = viewProvider.Get(Definition); View.Render(new ContentControlRenderContext(this)); } }