Adding RichTextBlockOverflow to FlipView

本文关键字:FlipView to RichTextBlockOverflow Adding | 更新日期: 2023-09-27 18:07:23

我有一个图书应用程序,我使用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++);
        }
    }

我在我的Initial UI方法中调用这段代码一旦UI更新了

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

如果我不调用最后一部分,我将得到第一个完整的页面。
如果我调用最后一部分,我得到第一页上的前3列,并将一个项目添加到FlipView,但第二页上没有显示文本,第四列消失

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

Adding RichTextBlockOverflow to FlipView

我认为你应该有更新你的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方法内置布局系统行为。然而,一般不建议这样做。这通常是不必要的如果过度使用可能会导致性能不佳. ...