RadTreeView Bind One Tree To Another

2 posts, 0 answers
  1. Marin
    Marin avatar
    1 posts
    Member since:
    Feb 2016

    Posted 28 Mar Link to this post

    Hello,I'm new in WPF. Let me explain you what is my case. So i have three RadTreeView, my point is, is it possible when I expand one of the the item in the first tree automatically to expand the same element in the others trees? And I have another question how to make every line in the RadTreeView to be different color?

    For example 1, 3, 5, 7 line to be gray, and 2,4,6,8 to be white.

     

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Mar Link to this post

    Hello Marin,

    Expanding / Selecting a particular item a RadTreeView in code can be achieved with GetItemByPath() / BringPathIntoView() / SelectitemByPath() / ExpandItemByPath() methods which are very similar.  Generally, if you organize your ViewModels to provide a Path property (or method) you can access (or select/expand) a particular RadTreeViewItem (the container for the viewmodel) with these functions.

    In your scenario, it is important whether the same (or some of the) viewmodels (objects) reside in multiple RadTreeView instances. If an object is both in trees A B and C, you need the paths for this object for every tree. You can store such paths, for example in dictionary per tree or in dictionary per object. Once such object is selected/expanded via its container (RadTreeViewItem) in tree A, you can use the Expanded / SelectionChanged event,  get this object , and expand/select/bring this object in the other trees, having its path available. Also, if you two-way bind the IsSelected property of the RadTreeViewItem to some boolean property of the object (viewModel), the object will be selected in all trees. 

    If your trees use entirely different sets of objects , you need to have matching dictionary - or way to say that object x in tree A matches the object y in tree B. Then use the same approach - when expand / select the first, get the matching second object and use its path in combination with the get-item-by-path functions.

    Regarding the alternation colors, this can be achieved with ItemContainerStyleSelector or ItemTemplateSelector - just select different template / style based on the index of the given object.

    Regards,
    Petar Mladenov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top