Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to make the StackPanel or DockPanel stretch to fit their containers in WPF?
  2. <!-- Data template for ListBox -->
  3. <DataTemplate DataType="{x:Type entities:Track}">
  4.   <StackPanel Orientation="Vertical">
  5.     <DockPanel>
  6.       <TextBlock DockPanel.Dock="Left" Text="Now playing" />
  7.       <TextBlock DockPanel.Dock="Right" Text="Time remaining" />
  8.     </DockPanel>
  9.     <TextBlock Text="{Binding Artist}" />
  10.     <TextBlock Text="{Binding Title}" />
  11.   </StackPanel>
  12. </DataTemplate>
  13.  
  14. ...
  15.  
  16. <ListBox
  17.   Grid.Column="1"
  18.   HorizontalAlignment="Stretch"
  19.   VerticalAlignment="Stretch" />
  20.        
  21. <ListBox ...>
  22.     <ListBox.ItemContainerStyle>
  23.         <Style TargetType="ListBoxItem">
  24.             <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
  25.         </Style>
  26.     </ListBox.ItemContainerStyle>