首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将FlowDocument BGImage转换为FixedDocument并在DocumentViewer中显示?

如何将FlowDocument BGImage转换为FixedDocument并在DocumentViewer中显示?
EN

Stack Overflow用户
提问于 2015-03-12 23:02:14
回答 1查看 555关注 0票数 2

我有一个带有背景图像的FlowDocument。目前,它不能在FlowDocumentReader中正确显示,因为当文档上下滚动时,背景图像保持在中心位置。如何将这个FlowDocument转换成FixedDocument,并在DocumentViewer中显示它,这样背景图像也会被修复?

我使用来自here的转换逻辑。但是它不显示FlowDocument.Background图像。

代码语言:javascript
复制
    private FixedDocument convert(FlowDocument flowDocument)
    {
        if (flowDocument == null)
            return null;
        var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
        var package = Package.Open(new MemoryStream(), FileMode.Create, FileAccess.ReadWrite);
        var packUri = new Uri("pack://temp.xps");
        PackageStore.RemovePackage(packUri);
        PackageStore.AddPackage(packUri, package);
        var xps = new XpsDocument(package, CompressionOption.NotCompressed, packUri.ToString());
        XpsDocument.CreateXpsDocumentWriter(xps).Write(paginator);
        FixedDocument doc = xps.GetFixedDocumentSequence().References[0].GetDocument(true);
        return doc;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-13 04:26:22

你写的

我有一个带有背景图像的FlowDocument。目前,它不能在FlowDocumentReader中正确显示,因为当文档上下滚动时,背景图像保持在中心位置。

不完全是对特定问题的回答,但为了避免这种情况,请将ImageBrush.ViewportUnits设置为BrushMappingMode.Absolute。然后,将ImageBrush.Viewport设置为所需的背景图像维数:

代码语言:javascript
复制
        <FlowDocumentReader ViewingMode="Scroll">
            <FlowDocument>
               <FlowDocument.Background>
                    <ImageBrush TileMode="Tile" Stretch="Fill" Viewport="0,0,1000,400" ViewportUnits="Absolute">
                        <ImageBrush.ImageSource>
                            <!--Image source here...-->
                        </ImageBrush.ImageSource>
                    </ImageBrush>

可选地将ImageBrush.Stretch设置为Stretch.Fill以填充指定的视图,并将ImageBrush.TileMode设置为TileMode.Tile以使背景图像重复。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29021961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档