【问题标题】:WPF/C# - Create FlowDocument Programmatically from XAML?WPF/C# - 从 XAML 以编程方式创建 FlowDocument?
【发布时间】:2011-05-17 17:45:25
【问题描述】:

我对 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 的方向吗?

【问题讨论】:

    标签: c# wpf flowdocument


    【解决方案1】:
    var flowDocument = 
        (FlowDocument)Application.LoadComponent(
            new Uri(@"SomeFlowDocument.xaml", UriKind.Relative));
    
    flowDocument.DataContext = this;
    
    Dispatcher.CurrentDispatcher.Invoke(
        DispatcherPriority.SystemIdle,
        new DispatcherOperationCallback(arg => null ), null);
    

    请参阅 this answer 了解最后一点的说明。

    它展示了如何从资源加载文档并使用绑定添加内容。

    【讨论】:

      猜你喜欢
      • 2013-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 2011-02-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      相关资源
      最近更新 更多