3

Windows 8.1/WP8.1 ユニバーサル アプリとして電子書籍リーダー タイプのアプリケーションを構築しています。私のテキストは、ソースとしてFlipViewを使用するに含まれていObservableCollection<FrameworkElement>ます。それぞれFrameworkElementが RichTextBlock または RichTextBlockOverflow のいずれかです。私の問題はFlipView、3 番目の要素の後に何も表示されなくなることです。

MDSN フォーラムで、同様の問題を抱えている人を見つけました。彼らの解決策は、問題がRichTextBlock/Overflowsビジュアル ツリーにないことを示しているように見えました。RichTextBlock/Overflowsただし、階層の上位に手動でアタッチして同じことを試みると、StackPanelその要素がすでに要素の子であることを示す例外が発生します(そして、それはObservableCollection追加された要素の子です) )。

どうすればこれを修正できますか? 私の RichTextBlocks とそのオーバーフローは、FlipView の ItemSource にあるため、既にツリーの一部であるべきではありませんか?

私のViewModelコードは以下です。Commanding を介して View から要素にアクセスできますが、これは最小限に抑えたいと思います。

EDIT
これを回避策で「修正」しました。ここでの問題は、FlipView がその子要素を仮想化することです。そのため、最初のページから十分離れた場所までスクロールすると、元の RichTextBlock が仮想化されてしまい、それに依存するすべての RichTextBlockOverflows のコンテンツが失われます。私の解決策は、FlipView の ItemsPanelTemplate を VirtualizingStackPanel から StackPanel に変更することでした。ここでの明らかな欠点は、仮想化のパフォーマンス上の利点が失われることです。すぐにうまくいくものを見つけたり受け取ったりしない限り、これを自己回答として投稿すると思います。

   private void BuildPagesNew()
    {
       //CurrentPage is a public property. It's the ObservableCollection<FrameworkElement>
        CurrentPage.Clear(); 
        RichTextBlockOverflow lastOverflow;            
        lastOverflow = AddOnePage(null);
        CurrentPage.Add(lastOverflow);            

        while(lastOverflow.HasOverflowContent)
        {
            lastOverflow = AddOnePage(lastOverflow);                           
        }
    }

    private RichTextBlockOverflow AddOnePage(RichTextBlockOverflow lastOverflow)
    {
        bool isFirstPage = lastOverflow == null;
        RichTextBlockOverflow rtbo = new RichTextBlockOverflow();

        if (isFirstPage)
        {
            RichTextBlock pageOne = new RichTextBlock();
            pageOne.Width = double.NaN;
            pageOne.Height = double.NaN;
            pageOne.FontSize = 16.00;
            pageOne.MaxWidth = this.TextboxMaxWidth;
            pageOne.MaxHeight = this.TextboxMaxHeight;
            pageOne.HorizontalAlignment = HorizontalAlignment.Left;
            pageOne.VerticalAlignment = VerticalAlignment.Top;
            pageOne.IsDoubleTapEnabled = false;
            pageOne.IsHitTestVisible = false;
            pageOne.IsHoldingEnabled = false;
            pageOne.IsTextSelectionEnabled = false;
            pageOne.IsTapEnabled = false;
            pageOne.SetValue(Helpers.Properties.HtmlProperty, CurrentBook.Pages[0].PageContent);
            pageOne.SetBinding(RichTextBlock.MaxWidthProperty, new Binding
                {
                    Source = TextboxMaxWidth,
                    Path = new PropertyPath("MaxWidth")
                });
            pageOne.SetBinding(RichTextBlock.MaxHeightProperty, new Binding
                {
                    Source = TextboxMaxHeight,
                    Path = new PropertyPath("MaxHeight")
                });

            pageOne.Measure(new Size(this.TextboxMaxWidth, this.TextboxMaxHeight));
            CurrentPage.Add(pageOne);
            if (pageOne.HasOverflowContent)
            {
                pageOne.OverflowContentTarget = rtbo;
                //set width and height here?
                rtbo.Measure(new Size(this.TextboxMaxWidth, this.TextboxMaxHeight));
            }
        }
        else
        {
            //set rtbo width and height here?
            //Maybe set maxheight and maxwidth bindings too
            if (lastOverflow.HasOverflowContent)
            {
                lastOverflow.OverflowContentTarget = rtbo;
                lastOverflow.Measure(new Size(this.TextboxMaxWidth, this.TextboxMaxHeight));
                rtbo.Measure((new Size(this.TextboxMaxWidth, this.TextboxMaxHeight)));
            }
            this.CurrentPage.Add(rtbo);
        }
        return rtbo;
    }
4

0 に答える 0