2010-08-26 51 views
1

我的WPF列表框应该有两列。右边的那个宽度应该是20,左边的列应该“填充”列表框的其余部分。如何创建带有变量左列和固定右列的WPF ListBox.ItemTemplate?

下面是列表框的定义:

<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> 

没有任何人有任何想法?任何帮助将不胜感激。

回答

2

尝试更新ItemContainerStyle如下:

<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> 
+0

要命。谢啦 ... – Johan 2010-08-26 18:51:33

相关问题