2013-03-06 98 views
1

我創建一個ListBoxItem行,每個都包含這3個項目:WPF DataTemplate的佈局

1) Button 
2) TextBox 
3) CheckBox 

我想他們這個樣子,其中的複選框碼頭向右:

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

但是相反我得到這個:

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

這裏是我的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> 


誠然,我不完全理解StackPanels/DockPanels /網格之間的細微差別,但任何幫助,將不勝感激!

回答

2

嘗試添加該到列表框中的定義:

HorizontalContentAlignment="Stretch" 

這將使項目使用列表框的整個水平寬度。

+0

這樣做。謝謝! – Matt 2013-03-06 19:26:48

+0

@Matt沒問題。 – 2013-03-06 19:31:43