开发者

Layout problem with pivot control

开发者 https://www.devze.com 2023-02-09 06:05 出处:网络
I have a Pivot, nothing in the slightest bit unusual and the listbox displays at the top left as I\'d expect:

I have a Pivot, nothing in the slightest bit unusual and the listbox displays at the top left as I'd expect:

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

but when I split this out to use a DataTemplate in Application.Resources, the listbox is centered, vertically and horizontally. How do I get it back to the top left?

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

I think I must be missing something obvious!

Thanks

Andrew


When you are creating the ListBox control itself, specify the explicit height and width and put it inside a StackPanel, for example.

Something like this:

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


Try setting HorizontalContentAlignment to Left and VerticalContentAlignment to Top on the Pivot.

0

精彩评论

暂无评论...
验证码 换一张
取 消