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);
        }
예제 #2
0
        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);
                    }
                }
            }
        }
예제 #3
0
 private void TryRegisterSelf()
 {
     if (!isAdded)
     {
         FieldValueProviderCollection collection = VisualTree.FindFieldValueProviderCollection(this);
         if (collection != null)
         {
             collection.Add(Definition.Identifier, this);
             isAdded = true;
         }
     }
 }
예제 #4
0
 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;
         }
     }
 }
예제 #5
0
        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));
            }
        }
예제 #6
0
        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));
            }
        }