2016-12-04 95 views
0

TreeView的HierarchicalDataTemplate似乎並不與GridSplitter很好地工作。我不完全知道在那裏實際的問題所在,但我懷疑ScrollViewerHierarchicalDataTemplate和GridSplitter

當前行爲: TreeView根據其項目進行調整。當更寬的項目展開時,TreeView會增長。無法通過網格分離器縮小尺​​寸或提高尺寸。 Horizo​​ntalAlignment = Stretch和ScrollViewer屬性似乎沒有影響到這一點。

預期行爲: TreeView將寬度調整爲GridSplitter,並在太小時顯示水平滾動條。

隨着似乎在截圖時,TreeView停留在其項目的最小寬度和不對齊到GridSplitter。

screenshot

<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> 

回答

1

問題是GridSplitter的ResizeBehavior。預期行爲可以通過ResizeBehavior="PreviousAndNext"

<GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" Width="4"/> 
+0

有趣!立即開始工作。我不知道這個屬性,因爲'GridSplitter'對我來說一直沒有任何問題。 – bytecode77