2011-02-05 168 views
0

我有一個支點,在沒有半點異常和列表框顯示在左側頂部爲我期望:佈局問題

<c:Pivot 
     Title="QUESTIONNAIRE" 
     ItemsSource="{Binding ViewModels}"> 

     <c:Pivot.HeaderTemplate> 
     <DataTemplate> 
      <TextBlock 
      Text="{Binding HeaderText}" /> 
     </DataTemplate> 
     </c:Pivot.HeaderTemplate> 

     <c:Pivot.ItemTemplate> 
     <DataTemplate> 
      <ListBox> 
      <ListBoxItem> 
       <TextBlock>ListboxItemText</TextBlock> 
      </ListBoxItem> 
      </ListBox> 
     </DataTemplate> 
     </c:Pivot.ItemTemplate> 

    </c:Pivot> 
    </Grid> 

但是當我拆了這一點要在Application.Resources中使用DataTemplate,列表框將居中,垂直和水平。我怎樣才能回到左上角?

<DataTemplate x:Name="datatemplateSample"> 
     <ListBox 
     ItemContainerStyle="{StaticResource styleSelect}" 
     SelectedIndex="{Binding Value}"> 
     <ListBoxItem> 
      <TextBlock>ListboxItemText</TextBlock> 
     </ListBoxItem> 
     </ListBox> 
    </DataTemplate> 

<c:Pivot 
     Title="QUESTIONNAIRE" 
     ItemsSource="{Binding ViewModels}"> 

     <c:Pivot.HeaderTemplate> 
     <DataTemplate> 
      <TextBlock 
      Text="{Binding HeaderText}" /> 
     </DataTemplate> 
     </c:Pivot.HeaderTemplate> 

     <c:Pivot.ItemTemplate> 
     <app:PivotDataTemplateSelector Content="{Binding}" /> 
     </c:Pivot.ItemTemplate> 

    </c:Pivot> 

    </Grid> 

我想我一定是失去了一些東西明顯!

感謝

安德魯

回答

0

例如,當您創建ListBox控件本身時,請指定明確的高度和寬度,並將其放在StackPanel之內。

事情是這樣的:

<DataTemplate x:Name="datatemplateSample"> 
    <StackPanel> 
     <ListBox 
     Height="480" Width="400" 
     ItemContainerStyle="{StaticResource styleSelect}" 
     SelectedIndex="{Binding Value}"> 
     <ListBoxItem> 
      <TextBlock>ListboxItemText</TextBlock> 
     </ListBoxItem> 
     </ListBox> 
    </StackPanel> 
</DataTemplate> 
+0

是的,這確實有效,但不完全符合動態佈局的精神! – amaca 2011-02-06 13:29:14

0

嘗試在Pivot設置HorizontalContentAlignmentLeftVerticalContentAlignmentTop

+0

我沒有試過,但沒有任何變化。 – amaca 2011-02-05 17:49:39