WPF / C#-从XAML以编程方式创建FlowDocument?

| 我对FlowDocument有点陌生,所以我非常愿意接受我做错了什么。如此说来,我编写了一个FlowDocument,它作为XAML文件存在于我的项目中。 就我刚刚开始而言,它非常简单:
<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>
现在,我想通过我的代码执行的操作是获取对该文档的引用,以便我可以将绑定设置为模型以设置图像源。有人可以指出我如何在后面的代码中实例化和加载FlowDocument的方向吗?     
已邀请:
var flowDocument = 
    (FlowDocument)Application.LoadComponent(
        new Uri(@\"SomeFlowDocument.xaml\", UriKind.Relative));

flowDocument.DataContext = this;

Dispatcher.CurrentDispatcher.Invoke(
    DispatcherPriority.SystemIdle,
    new DispatcherOperationCallback(arg => null ), null);
有关最后一点的解释,请参见此答案。 它显示了如何从资源加载文档以及如何使用绑定添加内容。     

要回复问题请先登录注册