2012-02-07 55 views
0

我創建了一個應用程序來跟蹤推文並將其綁定到列表框。listBox創傷性錯誤@ WP7

和,這裏是ListBox的XAML:

  <ListBox Margin="0,0,-12,0" x:Name="listBox1" ItemsSource="{Binding Items}" SelectionChanged="listBox1_SelectionChanged"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Horizontal" Margin="0,0,0,17"> 
          <!--Replace rectangle with image--> 
          <Image Height="100" Width="100" Source="{Binding DeveloperImage}" Margin="12,0,9,0"/> 
          <StackPanel Width="311"> 
           <TextBlock Text="{Binding DeveloperName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
           <TextBlock Text="{Binding DeveloperBirthday}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
          </StackPanel> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

,但是,當它被調試,它返回到這個序列:

長的空白 內容 空白

我想要的是:

僅限內容,內容沒有空白,內容沒有空白。

+0

你可以顯示封閉元素(網格?),也許是你得到什麼圖片,你想得到什麼? – 2012-02-07 07:11:38

+0

我想獲得乾淨的列表框,列表框的開始和結束之間沒有空格 – user1072976 2012-02-07 08:03:34

+0

您將不得不調整列表框的模板。 – 2012-02-07 08:06:36

回答

0

ListBox排列其子項的方式由其ItemsPanel確定。

您可以通過設置ItemsPanelTemplate來替換默認的ItemsPanel。

然後將每個孩子包裹在一個ItemContainer中。

您可以通過設置ItemContainerStyle來替換默認的ItemContainer。

最後,ListBox本身有一個邊界,填充和邊距,這些邊界影響了ItemsPanel的放置位置。

所以,如果你想調整列表框內容的位置,你首先必須找出應該修改哪些模板。一個快速的方法是使用Blend,因爲它會給你視覺反饋。