DockPanel doesn't use whole space in ListBox, but outside it does

461 Views Asked by At

In my Windows Phone application I'm using the DockPanel to align two buttons: one on the left side of the screen (PanoramaItem), second - on the right. This code works well:

<controls:PanoramaItem Header="page1">
   <panel:DockPanel>
      <Button  Content="Right"  panel:DockPanel.Dock="Right"/>
      <Button  Content="Left"  panel:DockPanel.Dock="Left"/>
   </panel:DockPanel>
</controls:PanoramaItem>

But if I want dock buttons this way in ListBox - both align to the left :(

<controls:PanoramaItem Header="page2">
   <ListBox Margin="0,0,-12,0" HorizontalContentAlignment="Stretch" 
        ItemsSource="{Binding Collection}" Height="418" VerticalAlignment="Top">
     <ListBox.ItemTemplate>
        <DataTemplate>
           <panel:DockPanel >
              <Button  Content="Right"  panel:DockPanel.Dock="Right"/>
              <Button  Content="Left"  panel:DockPanel.Dock="Left"/>
           </panel:DockPanel>
        </DataTemplate>
     </ListBox.ItemTemplate>
  </ListBox>
</controls:PanoramaItem>
1

There are 1 best solutions below

0
On BEST ANSWER

Add this inside the tag for list box:

<ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
    </Style>
</ListBox.ItemContainerStyle>