Silverlight 具有轴控制的布局问题

Silverlight 具有轴控制的布局问题,silverlight,windows-phone-7,Silverlight,Windows Phone 7,我有一个轴,没有任何异常,列表框显示在左上角,正如我所期望的: <c:Pivot Title="QUESTIONNAIRE" ItemsSource="{Binding ViewModels}"> <c:Pivot.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding HeaderText}

我有一个轴,没有任何异常,列表框显示在左上角,正如我所期望的:

    <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>
我想我一定错过了什么明显的东西

谢谢

Andrew

尝试在轴上将HorizontalContentAlignment设置为Left,将VerticalContentAlignment设置为Top。

例如,在创建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>

是的,这确实有效,但并不完全符合动态布局的精神!
<DataTemplate x:Name="datatemplateSample">
  <StackPanel>
      <ListBox
        Height="480" Width="400"
        ItemContainerStyle="{StaticResource styleSelect}"
        SelectedIndex="{Binding Value}">
        <ListBoxItem>
          <TextBlock>ListboxItemText</TextBlock>
        </ListBoxItem>
      </ListBox>
  </StackPanel>
</DataTemplate>