为什么stackpanel打破了我的pivotviewer?

时间:2011-03-16 17:05:50

标签: pivotviewer

我有一个工作的pivotviewer,有我自己组装的128张汽车图片。我使用网络上的许多教程中的一个来使其工作,并且它运作良好。然后我想我应该稍微装饰页面,所以我把pv所在的网格放在一个边界的stackpanel里面,上面有几个文本块来告诉它是什么。除了图像,一切都很好。注释掉stackpanel线,它完美无缺。

有什么想法吗?怎么会这么简单的失败呢?

以下是MainPage.xaml中的所有代码:

<StackPanel>
    <TextBlock
        FontSize="24"
        HorizontalAlignment="Center"
        VerticalAlignment="Top">
        Silverlight Pivotviewer Example
    </TextBlock>
    <TextBlock
        FontSize="16"
        HorizontalAlignment="Center"
        VerticalAlignment="top">
        Cool Automobiles
    </TextBlock>
    <Grid x:Name="LayoutRoot" Background="White">
        <pivoter:PivotViewer x:Name="pivotViewer" />
    </Grid>
</StackPanel>

3 个答案:

答案 0 :(得分:0)

您的网格“LayoutRoot”是您的主要布局控件。您需要将StackPanel包装在Grid控件中。

这样的事情:

<Grid x:Name="LayoutRoot" Background="White"
  <StackPanel>
    <TextBlock
        FontSize="24"
        HorizontalAlignment="Center"
        VerticalAlignment="Top">
        Silverlight Pivotviewer Example />
    <TextBlock
        FontSize="16"
        HorizontalAlignment="Center"
        VerticalAlignment="top">
        Cool Automobiles />
    <pivoter:PivotViewer x:Name="pivotViewer" />
  </StackPanel>
</Grid>

声明网格后,我会添加一些行,即0,1,2。然后我会布置你的Stackpanels,PivotViewer等。

希望这有帮助。

答案 1 :(得分:0)

这是一个已知问题。 StackPanel是一个无量纲元素。您需要将宽度和高度值添加到StackPanel,并且PivotViewer将开始正常工作。

答案 2 :(得分:0)

这就是我们所做的。我们在对话框的SizeChanged事件中添加了一个事件处理程序,然后调整了PivotViewer的大小。在Initialise或Loaded事件之后也调用它...看看你怎么样?

  void PivotDialog_SizeChanged( object sender, SizeChangedEventArgs e )
  {
     SizePivotViewer( );
     m_PivotViewer.UpdateLayout( );
  }

  private void SizePivotViewer( )
  {
     m_PivotViewer.Width = ActualWidth;
     m_PivotViewer.Height = ActualHeight - 20; // Magic number so text will display properly at bottom of Pivot!
  }