© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
stigzler

Have a WPF treeview stretch to fit its container

HI - having problems to achieve the above. My xaml:

 <Grid Margin="5">
     <Grid.Resources>
         <HierarchicalDataTemplate DataType="{x:Type viewmodels:GistViewModel}" ItemsSource="{Binding Path=GistFiles}">
             <TextBlock Text="{Binding GistFiles, Converter={StaticResource GistFilesToFirstFilenameConverter}}"></TextBlock>
         </HierarchicalDataTemplate>
         <DataTemplate DataType="{x:Type viewmodels:GistFileViewModel}">
             <TextBlock Text="{Binding Filename}"></TextBlock>
         </DataTemplate>
     </Grid.Resources>
     <TreeView x:Name="GistsTV" Grid.Column="0" ItemsSource="{Binding Gists}">
     </TreeView>            
 </Grid>
 <Grid Margin="5">
     <Grid.Resources>
         <HierarchicalDataTemplate DataType="{x:Type viewmodels:GistViewModel}" ItemsSource="{Binding Path=GistFiles}">
             <TextBlock Text="{Binding GistFiles, Converter={StaticResource GistFilesToFirstFilenameConverter}}"></TextBlock>
         </HierarchicalDataTemplate>
         <DataTemplate DataType="{x:Type viewmodels:GistFileViewModel}">
             <TextBlock Text="{Binding Filename}"></TextBlock>
         </DataTemplate>
     </Grid.Resources>
     <TreeView x:Name="GistsTV" Grid.Column="0" ItemsSource="{Binding Gists}">
     </TreeView>            
 </Grid>

It results in the attached image. The Treeview is the thin control at the bottom. Any advice?
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

WPF TreeView Fails to load ItemsSource
C#CC# / help
16mo ago
What WPF Treeview trigger happens after a user selects something?
C#CC# / help
4y ago
WPF Treeview HierarchicalDataTemplate on Type with sub-collection
C#CC# / help
2y ago
JSON Parsing to TreeView
C#CC# / help
2y ago