Custom page size output in XPS from WPF report

∥☆過路亽.° 提交于 2019-12-03 22:22:58

It seems to work when you wrap the user control (the report) inside another element, providing also the real size and not forgetting to put a background. I don't know exactly why, but the background seems to do the trick, along with the size.

public override DocumentPage GetPage(int pageNumber) {
    var page = new MyUserControl();

    Border wrapper = new Border();
    wrapper.Width = this.PageSize.Width;
    wrapper.Height = this.PageSize.Height;
    wrapper.Background = Brushes.White;

    wrapper.Child = page;

    wrapper.Measure(this.PageSize);
    wrapper.Arrange(new Rect(new Point(0, 0), this.PageSize));
    wrapper.UpdateLayout();

    return new DocumentPage(wrapper);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!