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

How to make HierarchichalDataTemplate fill cell

1 Answer 263 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 09 Sep 2013, 04:25 PM
I am using the HierarchicalDataTemplate in my RadTreeView. The content of the data template is a grid and the grid has a context menu specified. The problem is the grid does not fill the RadTreeView cell (it seems to size to the content) so the context menu only displays if you click on the content, not anywhere in the cell. Is there a way to force the template to fill the cell or is there a better way to implement data template specific context menus?

An example of one of my data templates is:
<HierarchicalDataTemplate DataType="{x:Type DTMLib:DTMHostsNode}" ItemsSource="{Binding Hosts}">
    <Grid Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
         
        <Image Grid.Column="0" Width="20" Height="20" Source="Images/Remote.png"/>
         
        <TextBlock Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Center" Margin="5,0,0,0"/>
         
        <telerik:RadContextMenu.ContextMenu>
            <telerik:RadContextMenu  Opening="RootContextMenuOpening">
                <telerik:RadMenuItem x:Name="ApplyCSVFileColumns" Header="Apply CSV File Columns" Click="ApplyRootCsvColumnsClick"/>
                <telerik:RadMenuItem x:Name="PlaybackCSVFiles" Header="Playback CSV Files" Click="PlaybackCsvFilesClick"/>
            </telerik:RadContextMenu>
        </telerik:RadContextMenu.ContextMenu>
    </Grid>
</HierarchicalDataTemplate>

My RadTreeView instance is:
<telerik:RadTreeView x:Name="ManagerTreeView" Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Stretch"/>

1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 09 Sep 2013, 04:50 PM
I found a solution, not sure if it is the only/best solution. If I set a style on all RadTreeViewItems and specify the HorizontalContentAlignment=Stretch it works. Note you also have to explicitly set the Grid background to Transparent in order to get mouse events in the grid. Here is the Style I used...

<Style TargetType="telerik:RadTreeViewItem">
    <Setter Property="IsExpanded" Value="True"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
Tags
TreeView
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or