2

I'm kind of new to this FlowDocument thing, so I'm perfectly willing to accept that I'm doing something wrong. With that said, I have written a FlowDocument which exists within my project as a XAML file.

It's very simple so far as I have just started on it:

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              ColumnWidth="400" FontSize="14" FontFamily="Georgia">
    <Table>
        <Table.Columns>
            <TableColumn Width="*" />
            <TableColumn Width="*" />
            <TableColumn Width="*" />
        </Table.Columns>

        <TableRowGroup>
            <TableRow>
                <TableCell>
                    <BlockUIContainer>
                        <Image Source="{Binding Logo}" />
                    </BlockUIContainer>
                </TableCell>
            </TableRow>
        </TableRowGroup>
    </Table>
</FlowDocument>

Now what I would like to do, via my code, is to get a reference to that document so I can set the binding to a model in order to set the image source. Can someone please point me in the direction of how to instanciate and load a FlowDocument in the code behind?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sonny Boy
  • 7,848
  • 18
  • 76
  • 104

1 Answers1

3
var flowDocument = 
    (FlowDocument)Application.LoadComponent(
        new Uri(@"SomeFlowDocument.xaml", UriKind.Relative));

flowDocument.DataContext = this;

Dispatcher.CurrentDispatcher.Invoke(
    DispatcherPriority.SystemIdle,
    new DispatcherOperationCallback(arg => null ), null);

See this answer for an explanation of that last bit.

It shows how to load the document from a resource and add content using bindings.

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115