0
TreeView的HierarchicalDataTemplate
似乎並不與GridSplitter
很好地工作。我不完全知道在那裏實際的問題所在,但我懷疑ScrollViewer
。HierarchicalDataTemplate和GridSplitter
當前行爲: TreeView根據其項目進行調整。當更寬的項目展開時,TreeView會增長。無法通過網格分離器縮小尺寸或提高尺寸。 HorizontalAlignment = Stretch和ScrollViewer屬性似乎沒有影響到這一點。
預期行爲: TreeView將寬度調整爲GridSplitter,並在太小時顯示水平滾動條。
隨着似乎在截圖時,TreeView停留在其項目的最小寬度和不對齊到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>
有趣!立即開始工作。我不知道這個屬性,因爲'GridSplitter'對我來說一直沒有任何問題。 – bytecode77