Get Visual Tree informations

Hello everybody,

I would like to code an application that can give me all the informations about the Visual Tree, ie the same kind of application as this one:

http://www.longhornblogs.com/zhanbos/archive/2004/11/23/7571.aspx


So I would like to be able to get all the type of the controls which compose/are the content of another one: the same thing which is displayed, on Interactive Designer, on the left part (under DocumentRoot) of the TimeLine Pane

Do you have any ideas


thanks






Answer this question

Get Visual Tree informations

  • shahapu

    Ok, here is how I do it:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Media;

    namespace __PossibilitesWPF
    {
    class Utility
    {
    private static StringBuilder sbListControls = new StringBuilder();

    public static StringBuilder GetVisualTreeInfo(Visual element)
    {
    if (element == null)
    {
    throw new ArgumentNullException(String.Format("Element {0} is null !", element.ToString()));
    }

    GetControlsList(element, 0);

    return sbListControls;
    }

    private static void GetControlsList(Visual control, int level)
    {
    const int indent = 4;
    int ChildNumber = VisualTreeHelper.GetChildrenCount(control);

    for (int i = 0; i <= ChildNumber - 1; i++)
    {
    Visual v = VisualTreeHelper.GetChild(control, i);

    sbListControls.Append(new string(' ', level * indent));
    sbListControls.Append(v.DependencyObjectType.Name);
    sbListControls.Append(Environment.NewLine);

    if (VisualTreeHelper.GetChildrenCount(v) > 0)
    {
    GetControlsList(v, level + 1);
    }
    }
    }
    }
    }



  • AmyHa

    John Gossman (Expression Interactive Designer Architect) has an example on his blog as well: http://blogs.msdn.com/johngossman/Default.aspx p=3

    I don't know anybody on the Expression Interactive Designer team who has not writtern some variation of this tree walk, for fun and otherwise :)

    Thanks,
    -Unni



  • Dave Neigler

    Kevin Moore has a VisualTreeViewer on his blog.

    See: http://blogs.msdn.com/okoboji/archive/2006/02/22/537226.aspx

    Michael


  • Ramachandran V

    Unni Ravindranathan - MSFT wrote:

    John Gossman (Expression Interactive Designer Architect) has an example on his blog as well: http://blogs.msdn.com/johngossman/Default.aspx p=3

    I don't know anybody on the Expression Interactive Designer team who has not writtern some variation of this tree walk, for fun and otherwise :)

    Thanks,
    -Unni



    Yes, but for I've seen he is using VisualOperations which is not avaliable with the Feb CTP :)


  • Get Visual Tree informations