1

我有一个书籍应用程序,我正在使用FlipView控件在用户当前正在阅读的书中任何选定章节的页面之间翻转。

我正在FlipView使用以下代码动态创建页面并将它们作为项目添加到控件中:

    private void CreateNewFlipPage(RichTextBlockOverflow columnContent, int page)
    {
        var fvItem = new FlipViewItem();
        var grid = GetOverflowGrid();   // Pre-formatted grid with 4 columns (index 0, 2, 4, and 6) and three 30 pixel spacer columns in between (index 1, 3, and 5)

        var overFlow1 = new RichTextBlockOverflow();
        var overFlow2 = new RichTextBlockOverflow();
        var overFlow3 = new RichTextBlockOverflow();
        var overFlow4 = new RichTextBlockOverflow();
        var pageText = new TextBlock
        {
            VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom,
            Opacity = 0.5,
            FontSize = 18.667,
            Margin = new Thickness(40, 0, 0, 0),
            Foreground = Application.Current.Resources["ApplicationPageTextOppositeBackgroundThemeBrush"] as SolidColorBrush,
            FontFamily = new FontFamily("Global User Interface"),
            Text = "Page " + page
        };

        overFlow4.Margin = new Thickness(0, 0, 0, 40);

        Grid.SetColumn(overFlow1, 0);
        Grid.SetColumn(overFlow2, 2);
        Grid.SetColumn(overFlow3, 4);
        Grid.SetColumn(overFlow4, 6);
        Grid.SetColumn(pageText, 6);

        grid.Children.Add(overFlow1);
        grid.Children.Add(overFlow2);
        grid.Children.Add(overFlow3);
        grid.Children.Add(overFlow4);
        grid.Children.Add(pageText);

        fvItem.Content = grid;
        FlipView.Items.Add(fvItem);

        overFlow1.OverflowContentTarget = columnContent;
        overFlow2.OverflowContentTarget = overFlow1;
        overFlow3.OverflowContentTarget = overFlow2;
        overFlow4.OverflowContentTarget = overFlow3;

        overFlow1.Measure(new Size(grid.ColumnDefinitions[0].ActualWidth, grid.ActualHeight));
        overFlow2.Measure(new Size(grid.ColumnDefinitions[0].ActualWidth, grid.ActualHeight));
        overFlow3.Measure(new Size(grid.ColumnDefinitions[0].ActualWidth, grid.ActualHeight));
        overFlow4.Measure(new Size(grid.ColumnDefinitions[0].ActualWidth, grid.ActualHeight));

        grid.UpdateLayout();

        if (overFlow4.HasOverflowContent)
        {
            CreateNewFlipPage(overFlow4, page++);
        }
    }

一旦 UI 更新,我在我的 Initial UI 方法中调用此代码:

...
if (column4Content.HasOverflowContent)
{
    CreateNewFlipPage(column4Content, 2);  // column4Content is a RTBO object
}
...

如果我不调用最后一部分,我会得到第一个完整页面,而没有其他任何内容。
如果我确实调用了最后一部分,我会在第一页上获得前 3 列,并将一个项目添加到FlipView,但第二页上没有显示任何文本,并且第 4 列消失了

我没有做什么来显示所有 RTBO 对象?

4

1 回答 1

0

我认为您也应该更新您的 FlipView布局。通过这种方式,HasOverflowContent属性知道它是否有任何溢出内容并返回它的真值(无论是真还是假)。

grid.UpdateLayout();

FlipView.UpdateLayout(); // Add this Line Here

if (column4Content.HasOverflowContent)
{
    CreateNewFlipPage(column4Content, 2);
}

但我对性能表示怀疑。在此处阅读UpdateLayout()文档:http:
//msdn.microsoft.com/en-US/library/windows/apps/windows.ui.xaml.uielement.updatelayout

...布局更新可以由应用程序代码强制执行,而不是使用UpdateLayout方法依赖内置布局系统行为。但是,通常不建议这样做。它通常是不必要的,如果过度使用会导致性能下降。...

于 2013-05-26T18:40:17.333 回答