private object FindOrBindKeyValue(FrameworkElement element, DependencyProperty property) { foreach (FrameworkElement ancestor in VisualTree.EnumerateAncestors(element, true)) { ModelDefinitionContainer container = UserModelPresenter.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 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; } } }