WPF: Customizing WPF PrintDialog in Framework 4.8 to Add Input Box for Page Selection
Our WPF application targets .NET 4.8.
The WPF application can generate run report which may include 12 pages.
A run report allows print. So far there is no option, and it always prints all 12 pages.
We like to add feature to allow select page numbers and only print those selected pages.
we notice that WPF PrintDialog allows set two options:
UserPageRangeEnabled and SelectedPagesEnabled
if users select "Pages" option and provide valid page range, click the Print button and Users will get PageFrom and PageTo values in PrintDialog.PageRange object.
However, if users select "Selection" option and there is no Input box in the Print dialog for users to provide selected page numbers.
Reference the link:
After selecting "Selection" option and click the Print button, users need to provide another Input Box and provided selected page numbers.
Just have a feeling that WPF PrintDialog in framework 4.8 does not provide full solution. Both Selection and Input box for the Selection option should be included in the PrintDialog.
Is there a possible to customize the WPF PrintDialog in Framework 4.8 to add the Input box for "Selection" option? thx!
PrintDialog printDialog = new PrintDialog();
printDialog.UserPageRangeEnabled = true;
printDialog.SelectedPagesEnabled = true;
if ( printDialog.ShowDialog() == false )
return;
DocumentPaginator paginator = DocumentSource.DocumentPaginator;
if (printDialog.PageRangeSelection == PageRangeSelection.SelectedPages)
{
SelectedDiaglog selectedDiaglog = new SelectedDiaglog();
if (selectedDiaglog.ShowDialog() == true) // If the user clicks Confirm
{
string input = selectedDiaglog.UserInput; // Get the string input by the user
var selectNum = input.Split(',').ToList();
//TODO: Use the page number to find the corresponding data for printing
}
}
else if (printDialog.PageRangeSelection == PageRangeSelection.UserPages)
{
paginator = new PageRangeDocumentPaginator(
paginator, printDialog.PageRange);
{
printDialog.PrintVisual(paginator.GetPage(pageNumber).Visual, "PrintReport");
}
}