WPF Print multiple pages from one view model

I am currently a little worried about the following issue. I have a user interface that basically shows graphics (canvas of lines, circles, ... these are all WPF objects). Depending on the choice the user makes in the menu, some items are deleted and some are added. Thus, the main image looks the same, but several changes have been made.

The user has the opportunity to select - say - 10 different "pages" by clicking the "Next / Previous" button.

I am using MVVM Light, and my ViewModel contains all graphic elements (all lines, ...).

Now I would like to print this graphic on several pages. The first page should contain graphics with changes from page 1, the second page should contain graphics with changes from page 2, etc. The actual number of pages is dynamic. I track this using the CurrentPage property and the PagesTotal property. Whenever I click the "Next" button, this will execute a command that will change the CurrentPage variable, and also make sure that the correct elements are displayed.

Now I would like to print this, but this is where I am stuck. I do not want to leave the MVVM zone and do some dirty work in the code, but I would refuse to draw everything again, as in the old days of GDI.

Any ideas are really welcome.

+1
source share
3 answers

, , . "WPF-", .

, , , .

0

UserControl, (, ). ViewModel UserControls, ViewModel DataConttext UserControl. , , DesiredHeight Width. WPF ( ).

+1

Essentially, this should be fairly simple if and only if your views work independently; those. Your ViewModel does not contain the UiElements that fit into your View.

A simple solution is to basically print your visual root. If you need to first encapsulate your views in a user control.

PrintDialog printDlg = new PrintDialog();
UserControl1 uc = new UserControl1();
printDlg.PrintVisual(uc, "User Control Printing."); 

Link

+1
source

All Articles