Exemplo n.º 1
0
        protected override void CreateVisualChildren()
        {
            object content = this.Content;

            if (content != null)
            {
                Control result;

                if (content is Control)
                {
                    result = (Control)content;
                }
                else
                {
                    DataTemplate dataTemplate = this.FindDataTemplate(content);

                    if (dataTemplate != null)
                    {
                        result = dataTemplate.Build(content);
                    }
                    else
                    {
                        result = new TextBlock
                        {
                            Text = content.ToString(),
                        };
                    }
                }

                result.TemplatedParent = null;
                this.AddVisualChild(result);
            }
        }
 public TypeTest()
 {
     if (DataContext != null)
     {
         Content = DataTemplate.Build(DataContext);
     }
 }
Exemplo n.º 3
0
        private void CreateChild()
        {
            object content = this.Content;

            this.ClearVisualChildren();

            if (content != null)
            {
                Control result;

                if (content is Control)
                {
                    result = (Control)content;
                }
                else
                {
                    DataTemplate dataTemplate = this.FindDataTemplate(content);

                    if (dataTemplate != null)
                    {
                        result = dataTemplate.Build(content);
                    }
                    else
                    {
                        result = new TextBlock
                        {
                            Text = content.ToString(),
                        };
                    }
                }

                var foo = this.TemplatedParent as TemplatedControl;

                if (foo != null)
                {
                    foo = foo.TemplatedParent as TemplatedControl;
                }

                result.TemplatedParent = foo;
                this.AddVisualChild(result);
            }

            this.createdChild = true;
        }