Question

I am creating ListBoxItem rows, each containing these 3 items:

1) Button
2) TextBox
3) CheckBox

I want them to look like this, where the checkbox docks to the right:

| 1 222           3 |
| 1 222222222     3 |
| 1 222222        3 |

But instead I am getting this:

| 1 222 3           |
| 1 222222222 3     |
| 1 222222 3        |

Here is my ItemTemplate:

<ListBox.ItemTemplate>
  <DataTemplate x:Name="foo" DataType="{x:Type bar}">
    <DockPanel LastChildFill="True">
      <Button DockPanel.Dock="Left" />
      <CheckBox DockPanel.Dock="Right" />
      <TextBlock Text="Foo" />
    </DockPanel>
  </DataTemplate>
</ListBox.ItemTemplate>


Admittedly, I don't fully understand the nuances of StackPanels/DockPanels/Grids, but any help would be appreciated!

Was it helpful?

Solution

Try adding this to the listbox definition:

HorizontalContentAlignment="Stretch"

This will allow the items to use the whole horizontal width of the listbox.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top