Grid in ItemTemplate does not stretch to available width?

3 posts, 1 answers
  1. Sam
    Sam avatar
    67 posts
    Member since:
    Jun 2011

    Posted 30 May 2012 Link to this post

    Hi there, 

    I've got a RadTreeView along these lines:

        x:Name="treeview" Background="Transparent" Margin="0, 6, 0, 0" BorderThickness="0"
        Grid.Row="1" IsEditable="True" IsTextSearchEnabled="True" BringIntoViewMode="HeaderAndItems"
        ItemsSource="{Binding Items}"
        SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
        <!-- Item Template -->
            <telerik:HierarchicalDataTemplate ItemsSource="{Binding ChildItems}">
                    <!-- Used to bind the treeview item to the data item for item tracking -->
                    <telerik:ContainerBindingCollection x:Name="BindingsCollection">
    Binding="{Binding IsInEditMode, Mode=TwoWay}" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    <TextBlock Text="{Binding Name}" />
                    <TextBlock Grid.Column="1" Margin="10, 0, 0, 0" Text="{Binding InstrumentCount}" />

    The tree is inside a grid column that also has an expander and a splitter associated with it, so the tree width itself expands to fit the available column space.

    The item template is meant to show a name, then on the right hand side of the tree view, show a number.

    The problem I'm having is that the Grid inside the HierarchicalDataTemplate does not expand to fill the available width, even if I explicitly set HorizontalAlignment to Stretch (which is the default anyway), so I don't get the numbers right-aligned as required.

    I can't use a fixed width either.

    Is there any way to get the Grid inside the ItemTemplate to take up all available width on the control, as the focus and selected visuals do, or is this not possible?



  2. Answer
    Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 04 Jun 2012 Link to this post

    Hi Sam,

    You'll need to set the RadTreeViewItems HorizontalContentAlignment to Stretch like so:
      <Style TargetType="telerik:RadTreeViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />

    Give this a try and let us know if it helps or if we can further assist you.

    Tina Stancheva
    the Telerik team

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

  3. Sam
    Sam avatar
    67 posts
    Member since:
    Jun 2011

    Posted 04 Jun 2012 Link to this post

    Hi Tina, that works like a charm! Thanks for providing a solution.


Back to Top