tags:

views:

9

answers:

1

My WPF Listbox should have two columns. The one on the right should have a width of say 20 and the left column should 'fill' the rest of the listbox.

Here is the listbox definition:

   <ListBox ItemsSource="{Binding Path=Stuff}">
      <ListBox.ItemTemplate>
        <DataTemplate>
           <DockPanel LastChildFill="True">
             <TextBlock Text="{Binding Path=Count}" DockPanel.Dock="Right" Width="20">
             </TextBlock>
             <TextBlock Text="{Binding Path=Name}">
             </TextBlock>
           </DockPanel>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>

Does anybody have any idea? Any help would be greatly appreciated.

+1  A: 

Try updating the ItemContainerStyle as follows:

<ListBox x:Name="listBox">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <DockPanel LastChildFill="True">
                <TextBlock Text="{Binding Path=Count}" DockPanel.Dock="Right" Width="20">
                </TextBlock>
                <TextBlock Text="{Binding Path=Name}">
                </TextBlock>
            </DockPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>

</ListBox>
karmicpuppet
Awsome. thanks man ...
Johan