WPF TreeView는 루트 루트의 붕괴시 이전에 사용 된 공간을 붕괴시키지 않습니다.
-
18-09-2019 - |
문제
ItemTemplate의 DataTemplate을 사용하여 ListBox에 표시하는 다양한 수집 속성이있는 객체가 있습니다. 해당 DataTemplate에는 ListBoxItem에 표시되는 항목을 나타내는 Root TreeViewItem의 TreeViewItem과 같은 다양한 속성을 표시하는 TreeView가 있습니다. 내 문제는 이것입니다 : ListBoxItems는 DataTemplate 내에서 완전히 확장 된 TreeView의 수직 크기를 가지고 있습니다. ListBoxItems에 최소 크기가 가능하도록이를 변경하는 방법이 있습니까?
내 xaml :
<ListBox x:Name="ShackList" ItemsSource="{Binding}" ToolTip="Right click for options" SelectionMode="Single">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type model:ShackConfigurationRepository}">
<TreeView BorderThickness="0" Margin="0">
<TreeView.Resources>
<Style x:Key="deviceRepoNodeStyle" TargetType="{x:Type TreeViewItem}">
<Setter Property="Margin" Value="3"/>
<Setter Property="ContextMenu" Value="{StaticResource deviceTypeTreeViewItemContextMenu}"/>
</Style>
</TreeView.Resources>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="Resources/Shack_64x64_72.png" Height="24" Width="24"/>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=ShackName}" />
</StackPanel>
</TreeViewItem.Header>
<!--
The 'Tag' attribute of the following TreeViewItems is a value of
DeviceType used to control which collection gets set as the content
of the device list.
-->
<TreeViewItem Header="Pendants" Tag="PENDANT" Selected="ShackDevice_Selected" DataContext="{Binding}" Style="{StaticResource deviceRepoNodeStyle}" PreviewMouseRightButtonDown="DeviceTreeNode_PreviewMouseRightButtonDown"/>
<TreeViewItem Header="Oscillators" Tag="OSCILLATOR" Selected="ShackDevice_Selected" DataContext="{Binding}" Style="{StaticResource deviceRepoNodeStyle}" PreviewMouseRightButtonDown="DeviceTreeNode_PreviewMouseRightButtonDown"/>
<TreeViewItem Header="Thru-Arc-Tracking" Tag="TAT" Selected="ShackDevice_Selected" DataContext="{Binding}" Style="{StaticResource deviceRepoNodeStyle}" PreviewMouseRightButtonDown="DeviceTreeNode_PreviewMouseRightButtonDown"/>
<TreeViewItem Header="Travel" Tag="TRAVEL" Selected="ShackDevice_Selected" DataContext="{Binding}" Style="{StaticResource deviceRepoNodeStyle}" PreviewMouseRightButtonDown="DeviceTreeNode_PreviewMouseRightButtonDown"/>
</TreeViewItem>
</TreeView>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
해결책
창에있는 모든 스크롤 뷰어의 최소 높이와 너비를 정의하는 창자 자원에 정의 된 스크롤 뷰어 스타일이 있었으며 ListBoxItems가 내부적으로 스크롤 뷰어를 사용한다는 것을 알지 못했습니다.
제휴하지 않습니다 StackOverflow