Binding to IsExpanded

3 posts, 1 answers
  1. Tim
    Tim avatar
    114 posts
    Member since:
    Aug 2011

    Posted 07 Dec 2011 Link to this post

    Hello.

    I've read several forum entries concerning this and it does not sound good:
    "and with latest versions of RadTreeListView binding to IsExpanded is not supported."
    After this I've read something about StyleSelectors and some other stuff about RowLoaded events...

    So, my question: What is the best way to do it with the current version?
    Thanks a lot for any kind of information!!!

    All the best,
    Tim.
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Dec 2011 Link to this post

    Hi Tim,

     
    You could  bind the "IsExpanded" property using a RowStyleSelector like so: 

    1. Create a StyleSelector (you need to have a property IsExpanded for the bound item):

    public class CustomStyleSelector : StyleSelector
        {
            public override Style SelectStyle(object item, DependencyObject container)
            {
                if(container is TreeListViewRow)
                {
        
                    if(item is ClientCategory)
                    {
                        Style style = new Style() { TargetType=typeof(TreeListViewRow)};
        
                        style.Setters.Add(new Setter(TreeListViewRow.IsExpandedProperty, ((ClientCategory)item).IsExpanded));
        
                        return style;
                    }
                }
                return base.SelectStyle(item, container);
            }
        }

    2. Then apply this style as a RowStyleSelector for the TreeListView:

    <Grid.Resources>
                <local:CustomStyleSelectorx:Key="CustomSelector"/>
    </Grid.Resources>  ...
    <telerik:RadTreeListView x:Name="tlv" RowStyleSelector="{StaticResource CustomSelector}"/>

    This is the best way to do it with the current version.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Tim
    Tim avatar
    114 posts
    Member since:
    Aug 2011

    Posted 08 Dec 2011 Link to this post

    Didie, thanks A LOT!!!
    All the best,Tim.
Back to Top