Hello Telerik team,
I have written the following "Feature Request": ScheduleView: Provide methods to print its content with full paging Support.
At the moment I'm trying to print the "WeekView" (seven days) on two pages. On the first page the first four days and on the second the rest. To realize this I use a hidden RadScheduleView (name: printScheduleView). My plan is to create an image for each page. Currently I am using the PrintVisual method, but later I would like to use the PrintDocument method (public abstract DocumentPage GetPage(int pageNumber)).
Before the PrintVisual method is called, printScheduleView must be rendered correctly, which currently only works with a timer. printScheduleView.UpdateLayout method could not solve the problem. Even a dirty DoEvents (UIElement.UpdateLayout Method) didn't solve the problem completely.
The sample project on my OneDrive account shows the bad behavior.
Can you please help me find a good solution?
Regards,
Marco
6 Answers, 1 is accepted
Thanks for the extensive information. I will check it a bit later and will get back in this forum tomorrow.
Regards,
Martin Ivanov
Progress Telerik
The RadScheduleView control needs some time to get rendered. This is why when you call PrintVisual() method, the picture is wrong. The rendering of the control is not yet completed and only some of its parts are rendered as expected. To resolve this, you can move the Measure(), Arrange() and UpdateLayout() methods after all settings of the scheduleview and then call the PrintVisual() method in a Dispatcher action with a low priority. This will delay the opening of the file dialog that freezes the UI and gives the control some additional time to be rendered. Here is an example in code:
private
void
btnPrint_Click(
object
sender, RoutedEventArgs e)
{
_printDlg =
new
PrintDialog();
if
(_printDlg.ShowDialog() ==
true
)
{
PrintCapabilities capabilities = _printDlg.PrintQueue.GetPrintCapabilities(_printDlg.PrintTicket);
double
printWidht = capabilities.PageImageableArea.ExtentWidth - 50;
double
printHeight = capabilities.PageImageableArea.ExtentHeight - 50;
Size size =
new
Size(printWidht, printHeight);
this
.printScheduleView.MinTimeRulerExtent = printHeight - 70;
this
.printScheduleView.MaxTimeRulerExtent = printHeight - 70;
this
.printScheduleView.ViewDefinitions[0].VisibleDays = 4;
MainViewModel viewModel = (MainViewModel)
this
.DataContext;
this
.printScheduleView.AppointmentsSource =
new
List<Appointment>(viewModel.Appointments);
this
.printScheduleView.Measure(size);
this
.printScheduleView.Arrange(
new
Rect(size));
this
.printScheduleView.UpdateLayout();
Dispatcher.BeginInvoke(
new
Action(() => {
_printDlg.PrintVisual(
this
.GetImageFromElement(
this
.printScheduleView),
"Test Print"
);
}), (DispatcherPriority)5);
}
}
Regards,
Martin Ivanov
Progress Telerik
Hello Martin,
I have adapted my sample project on my OneDrive with your solution. Unfortunately, even with BeginInvoke the control doesn't get enough time for rendering. The described problem is visible in the PDF files on my OneDrive, [ViewDefinitionName]First.pdf for the first and [ViewDefinitionName]Second.pdf for the second attempt.
Regards,
Marco
I check the project and I'm looking for a solution - will get back you as soon as possible.
Thanks for understanding.
Regards,
Kalin
Progress Telerik
Sorry for the delay. The reason for the incorrect images is the transition animation played right after the AppointmentsSource is changed and the ActiveViewDefinition is changed. Removing the transition should resolve this, however with the current implementation the only to do so would be to modify the ControlTemplate - you would need to find the TransitionControl with x:Name "PART_TransitionControl" and set the Transition property to null.
I have modified the project in order to demonstrate the exact approach - hope this will work for you.
Regards,
Kalin
Progress Telerik