IsExpandable Is not hiding the Expand Button

4 posts, 0 answers
  1. Josh
    Josh avatar
    5 posts
    Member since:
    Jun 2012

    Posted 22 Jan 2013 Link to this post

    I'm having issues with getting the IsExpandable property to be respected. Basically when my "Parent" has no children, I don't want the expand togglebutton to be shown. Below is some sample xaml that I am using. The resulting grid has the details column fully populated with the togglebuttons when there should be at least one without the button. I've stepped through my StyleSelector code and it is returning the proper style. But it doesn't appear to have any affect. What am I doing wrong?

    <UserControl ...>
        <UserControl.Resources>
            <Style x:Key="NoChildrenRowStyle" TargetType="telerik:GridViewRow">
                <Setter Property="IsExpandable" Value="False"/>
            </Style>
      
            <Style x:Key="HasChildrenRowStyle" TargetType="telerik:GridViewRow">
                <Setter Property="IsExpandable" Value="True"/>
            </Style>
    </UserControl.Resources>
      
     <local:RowStyleSelector x:Key="RowStyleSelector"
             NoChildrenStyle="{StaticResource NoChildrenRowStyle}"
             HasChildrenStyle="{StaticResource HasChildrenRowStyle}"/>
      
    <telerik:RadGridView ItemsSource="{Binding ParentsCollectionView}"
            RowIndicatorVisibility="Collapsed"
            AutoGenerateColumns="False"
            RowStyleSelector="{StaticResource RowStyleSelector}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewToggleRowDetailsColumn />
                    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/>
                    <telerik:GridViewDataColumn Header="Age" DatatMemberBinding="{Binding Age}"/>
                </telerik:RadGridView.Columns>
                <telerik:RadGridView.RowDetailsTemplate>
                    <DataTemplate>
                        <ListBox ItemsSource="{Binding Children}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <TextBlock Text="{Binding Name}"/>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>  
                        </ListBox>
                    </DataTemplate>
                </telerik:RadGridView.RowDetailsTemplate>
            </telerik:RadGridView>
    </UserControl>
  2. Yoan
    Admin
    Yoan avatar
    1182 posts

    Posted 24 Jan 2013 Link to this post

    Hello Josh,

    I would suggest you to check our custom hierarchy demo for more info. Although it is for Silverlight, you can find the same demo in your local copy of WPF demos.


    Regards,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Josh
    Josh avatar
    5 posts
    Member since:
    Jun 2012

    Posted 24 Jan 2013 Link to this post

    I'm sorry, but that answer is not helpful at the least. I've already seen the demo, I have a RowStyleSelector and it isn't working. The only difference I can see from your sample to mine is that I'm using a StyleSelector defined in code rather than xaml. But that shouldn't matter and if it does, then that's a huge shortcoming for you controls.

    For clarity, I have a styleselector like this:

    public class MyRowStyleSelector : StyleSelector
    {
        public Style HasChildrenStyle { get; set; }
        public Style NoChildrenStyle { get; set; }
     
        public override Style SelectStyle(object item, System.Windows.DependencyObject container)
        {
            if (...)
            {
                return HasChildrenStyle;
            }
     
            return NoChildrenStyle;
        }
    }
  4. Yoan
    Admin
    Yoan avatar
    1182 posts

    Posted 24 Jan 2013 Link to this post

    Hi Josh,

    Indeed, you can try using a hierarchy child template instead of using RowDetails. Please find attached a sample project that shows you the approach.

    Regards,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top