Domanda

Ho alcuni oggetti con le varie proprietà di raccolta che sto visualizzazione in un ListBox utilizzando un DataTemplate per l'ItemTemplate. Da che DataTemplate è un TreeView che visualizza le varie proprietà come TreeViewItem figli di un TreeViewItem radice che rappresenta gli elementi essendo visualizzati nella ListBoxItem. Il mio problema è questo: i ListBoxItems hanno la dimensione verticale della TreeView completamente espanso all'interno del DataTemplate. C'è un modo per cambiare questo modo che i ListBoxItems avranno la dimensione minima possibile?

Il mio 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>
È stato utile?

Soluzione

ho avuto uno stile per ScrollViewer definito nelle risorse della finestra che stava definendo l'altezza e la larghezza minima per tutti i ScrollViewers nella finestra, e non mi rendevo conto che ListBoxItems utilizzano ScrollViewers internamente.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top