This is a migrated thread and some comments may be shown as answers.

Grid in ItemTemplate does not stretch to available width?

2 Answers 370 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sam
Top achievements
Rank 1
Sam asked on 30 May 2012, 09:22 AM
Hi there, 

I've got a RadTreeView along these lines:

<telerik:RadTreeView
    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:RadTreeView.ItemTemplate>
        <telerik:HierarchicalDataTemplate ItemsSource="{Binding ChildItems}">
            <telerik:ContainerBinding.ContainerBindings>
                <!-- Used to bind the treeview item to the data item for item tracking -->
                <telerik:ContainerBindingCollection x:Name="BindingsCollection">
                    <telerik:ContainerBinding
PropertyName="IsInEditMode"
Binding="{Binding IsInEditMode, Mode=TwoWay}" />
                </telerik:ContainerBindingCollection>
            </telerik:ContainerBinding.ContainerBindings>
 
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
 
                <TextBlock Text="{Binding Name}" />
 
                <TextBlock Grid.Column="1" Margin="10, 0, 0, 0" Text="{Binding InstrumentCount}" />
            </Grid>                                      
        </telerik:HierarchicalDataTemplate>
    </telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>


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?

Thanks,

Sam




2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 04 Jun 2012, 10:50 AM
Hi Sam,

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

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

Regards,
Tina Stancheva
the Telerik team

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

0
Sam
Top achievements
Rank 1
answered on 04 Jun 2012, 11:42 PM
Hi Tina, that works like a charm! Thanks for providing a solution.

Cheers,

Sam
Tags
TreeView
Asked by
Sam
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Sam
Top achievements
Rank 1
Share this question
or