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.
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>
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论