Pregunta

Tengo algunos objetos con varias propiedades de la colección que estoy mostrando en un cuadro de lista utilizando una placa de datos para el elemento Template. Dentro de esa placa de datos hay una vista de árbol que muestra varias propiedades como TreeViewitem Children of a Root TreeViewitem que representa los elementos que se muestran en ListBoxItem. Mi problema es este: los listboxItems tienen el tamaño vertical de la vista de árbol completamente expandida dentro de la placa de datos. ¿Hay alguna forma de cambiar esto para que ListBoxItems tenga el tamaño mínimo posible?

Mi 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>
¿Fue útil?

Solución

Tenía un estilo para ScrollViewer definido en los recursos de la ventana que definía la altura y el ancho mínimo para todos los ScrollViewers en la ventana, y no me di cuenta de que ListBoxItems usa ScrollViewers internamente.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top