WPF 从单个视图模型打印多页 [英] WPF Printing multiple pages from a single View Model

查看:55
本文介绍了WPF 从单个视图模型打印多页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有点被以下问题困扰.我有一个用户界面,它基本上显示了一个图形(由线、圆等组成的画布……这些都是 WPF 对象).根据用户在菜单中所做的选择,一些项目会被删除,一些会被添加.所以基本的图片看起来是一样的,只是做了一些修改.

I am currently a little bit troubled by the following problem. I have a user interface which basically shows a graphic (a canvas made of Lines, Circles, ... these are all WPF objects). Depending on the selection a user makes in the menu, some items get deleted and some get added. So the basic image looks the same, but a few modifications are made.

用户可以通过单击下一个/上一个按钮来选择 - 例如 - 10 个不同的页面".

The user has the possibility to select - say - 10 different "pages" by clicking a Next/Previous Button.

我正在使用 MVVM Light,我的 ViewModel 包含图形的所有项目(所有线条,...).

I am using MVVM Light and my ViewModel contains all the items of the graphic (all Lines, ...).

现在我想将该图形打印到多个页面.第一页应包含从第 1 页更改的图形,第二页包含从第 2 页更改的图形,依此类推.实际的页数是动态的.我用一个属性 CurrentPage 和一个属性 PagesTotal 跟踪这个.每当我按下下一步"按钮时,都会导致执行一个命令,该命令将更改变量 CurrentPage 并确保显示正确的项目.

Now I would like to print that graphic to multiple pages. The first page should contain the graphic with changes from page 1, the second page contains the graphic with changes from page 2 and so on. The actual number of pages is dynamic. I track this with a property CurrentPage and a property PagesTotal. Whenever I push the "Next" button, this causes a command to be executed which will change the variable CurrentPage and also makes sure that the correct items are displayed.

现在我想打印这个,但这就是我被卡住的地方.我不介意离开 MVVM 区域并在代码隐藏中做一些肮脏的工作,但我会拒绝像旧 GDI 时代那样再次绘制所有内容.

Now I would like to print this but this is where I'm stuck. I dont' mind leaving the MVVM zone and doing some dirty work in code-behind but I would refuse to draw everything again like in the old GDI days.

任何想法都非常受欢迎.

Any ideas are really welcome.

推荐答案

好吧,我必须管理我现在切换回仅通过代码进行打印.我真的很喜欢这样做WPF 风格",但处理多页问题太麻烦了.

Alright, I have to admin that I now switched back to doing the printing through code only. I would have really liked doing it "WPF-style" but handling the multiple pages issue was just too much trouble.

无论如何,仍然有一个关于打印输出的问题,但这将是另一个问题.

Anyway, there is still one issue regarding the printout left but this will be another question.

这篇关于WPF 从单个视图模型打印多页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆