WPF DocumentViewer将文档显示为字节数组

时间:2017-02-11 20:21:34

标签: c# wpf documentviewer

这可能是一个愚蠢的问题,但我想知道是否可以从字节数组中在WPF的DocumentViewer控件中显示文档。

如果没有,有人可以举例说明控件通常用于显示文档吗?我似乎无法找到一个体面的例子。

1 个答案:

答案 0 :(得分:0)

关于安排不同的UIElements:

        FixedDocument fixedDocument = new FixedDocument();
        DocumentViewer dv = new DocumentViewer() { Document = fixedDocument };
        this.Content = dv;

        var page1 = new FixedPage() { Width = 600, Height = 800 };
        PageContent page1Content = new PageContent() { Child = page1 };
        var sp = new StackPanel();
        sp.Children.Add(new TextBlock
        {
            Text = "Title",
            FontSize = 30,
            Margin = new Thickness(100, 50, 0, 70)
        }); 
        sp.Children.Add(new TextBlock
        {
            Text = "The quick brown fox jumps over the lazy dog...",
            FontSize = 15,
            Margin = new Thickness(10, 0, 0, 10)
        }); 

        Rectangle rect = new Rectangle();
        rect.Width = 150;
        rect.Height = 150; 
        rect.Fill = Brushes.Black;
        sp.Children.Add(new Rectangle
        {
            Width = 150,
            Height = 150,
            Fill = Brushes.Black
        }); 
        page1.Children.Add(sp);
        fixedDocument.Pages.Add(page1Content);