trouble displaying flowdocument

77 Views Asked by At

I'm having some problems displaying the contents of a flowdocument in a flowdocumentscrollviewer. I create a generic list that holds a class which contains an int, string and a flowdocument.

In a WPF listbox, I am trying to display the flowdocument in the scrollviewer alongside a button. I use the following function called from the WPF window constructor to populate the listbox

private void populateListBox()
{
    foreach(Element el in _notesList)
    {
        StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;
            Button b = new Button();
            b.Content = el._theID;
            sp.Children.Add(b);
            FlowDocumentScrollViewer fdsv = new FlowDocumentScrollViewer();
            fdsv.MinWidth = 400;
            fdsv.Document = el._theDoc;
            sp.Children.Add(fdsv);
            ListBoxItem lbi = new ListBoxItem();
            lbi.Content = sp;
            noteList.Items.Add(lbi);
        }
    }

But the code does not work. There are no errors but the scrollviewers are just blank in the listbox. I also tried storing the classes in an ObservableList and binding to the Document property but that didn't work either.

Any ideas what is happening?

1

There are 1 best solutions below

0
On

Nevermind. I figured it out.

Further down in the program execution I was copying the flowdocument blocks to a merged document in a foreach statement. This doesn't work even if you use Blocks.ToList(). I eventually found a way to copy the document contents to another document here.