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 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;
         }
     }
 }