Reputation: 14820
TreeView's HierarchicalDataTemplate
doesn't seem to work well with GridSplitter
. I'm not exactly sure where actual issue lies, but I'm suspecting ScrollViewer
.
Current behaviour: The TreeView adapts its with according to its items only. When an item that is wider expands, the TreeView grows. It cannot be downsized or upscaled by the grid splitter. HorizontalAlignment=Stretch and ScrollViewer properties don't seem to affect this.
Expected behavior: The TreeView adapts the width to the GridSplitter and displays a horizontal scroll bar when too small.
As seem on the screenshot, the TreeView stays at its item's minimum width and doesn't align to the GridSplitter.
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="250" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TreeView Name="treMain" BorderThickness="0" ItemsSource="{Binding TreeViewSections}" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:TreeViewEntry}" ItemsSource="{Binding Items}">
<StackPanel Orientation="Horizontal" Margin="5,3">
<Image Margin="0,0,5,0">
<Image.Style>
<Style TargetType="Image">
<Setter Property="Source" Value="{Binding Icon}" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}" Value="True">
<Setter Property="Source" Value="{qc:Binding '$P.ExpandedIcon == null || $P.Items.Count == 0 ? $P.Icon : $P.ExpandedIcon', P={Binding}}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{Binding Text}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
<EventSetter Event="MouseDoubleClick" Handler="treMain_MouseDoubleClick" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Upvotes: 0
Views: 429
Reputation: 35646
the issue is ResizeBehavior of GridSplitter. Expected behavior can be achieved with ResizeBehavior="PreviousAndNext"
<GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" Width="4"/>
Upvotes: 3