Please start using our more robust New Forum, we have put this old forum in archive mode. Thanks.

Welcome Guest Search | Active Topics | Log In

Tag as favorite
Issue in printing the Gantt table & chart
#1 Posted : Saturday, February 08, 2014 6:36:15 AM

Posts: 6


Good day!,

What we are currently facing is , we are getting an exception when we try to expand all nodes of gantt table (by default we are showing the gantt table in collapsed form) and try to print it

the exception is as follows

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Timestamp: Sat, 8 Feb 2014 10:51:11 UTC

Message: Unhandled Error in Silverlight Application Dialogs must be user-initiated. at System.Windows.Printing.PrintDocument.PrintInternal(String documentName, PrinterFallbackSettings printerFallbackSettings, Boolean useDefaultPrinter)
at System.Windows.Printing.PrintDocument.Print(String documentName)
at System.Windows.Printing.Reporting.Report.Print()
at PPLGanttProj.MainPage.Print_Closed(Object sender, EventArgs e)
at System.Windows.Controls.ChildWindow.OnClosed(EventArgs e)
at System.Windows.Controls.ChildWindow.Close()
at System.Windows.Controls.ChildWindow.set_DialogResult(Nullable`1 value)
at PPLGanttProj.PrintWindow.OKButton_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
Line: 1
Char: 1
Code: 0
URI: http://localhost/EwQMS_Inst1/common/ProjectPlanner/EwQMS4.0/PPL/GanttTaskGrid.aspx?ProjId=25&UsrId=123&ClsId=2&Mode=tracking&RespType=0&languageId=1&ProductId=10&SiteId=1&IsTemplate=0

Below is our code for printing

private void btnPrint_Click(object sender, RoutedEventArgs e)

PrintWindow Print = new PrintWindow();
Print.Closed += new EventHandler(Print_Closed);


void Print_Closed(object sender, EventArgs e)

if (gintPrintOption == 6) return;
busyIndicator.IsBusy = true;
PrintOptions prtopt = PrintOptions.WYSIWYG;
//PrintOptions is enum type
switch (gintPrintOption)
case 0:
prtopt = PrintOptions.Chart;
case 1: prtopt = PrintOptions.VisibleChart;
case 2: prtopt = PrintOptions.WYSIWYG;
case 3:
prtopt = PrintOptions.Full;
case 4: prtopt = PrintOptions.Full2;
case 5: prtopt = PrintOptions.Grid;

double width = 800;
double height = 900;

GanttPrintVisuals visuals = new GanttPrintVisuals(this.gcTaskGrid, prtopt, Size.Empty);

List<UIElement> list = new List<UIElement>();

int i = 0;
while (visuals.IsPageCountValid == false)
UIElement pageVisual = visuals.GetVisual(i++, width, height);

// Convert the UIElement to an Image immediately and add it to a Canvas:
WriteableBitmap w = new WriteableBitmap(pageVisual, new TranslateTransform());

Canvas c = new Canvas();

c.Children.Add(new Image() { Source = w, MaxWidth = width, MaxHeight = height, Stretch = Stretch.None });


Report.ItemsSource = list;


DateTime ComputedStartTime = DateTime.MinValue;
DateTime ComputedEndTime = DateTime.MinValue;
private void PrintAllTasksInProjectGantt()

ComputedStartTime = this.gcTaskGrid.GanttChart.ComputedStartTime;
ComputedEndTime = this.gcTaskGrid.GanttChart.ComputedEndTime;
// First compute the earliest start and the latest end in all the tasks.
DateTime startTimes = ((ActivitiesCollection)this.gcTaskGrid.Model.Activities).StartTime;
DateTime endTimes = ((ActivitiesCollection)this.gcTaskGrid.Model.Activities).EndTime;
// Set the end time.
SetEndTime(endTimes, this.gcTaskGrid);
// Set the start time.
// this.gcTaskGrid.Print(PrintOptions.Chart);
private void SetEndTime(DateTime selEnd, GanttBase gantt)
DateTime curStart = gantt.GanttChart.ComputedStartTime;
DateTime curEnd = gantt.GanttChart.ComputedEndTime;

if (selEnd == gantt.GanttChart.ComputedEndTime)

if (selEnd > curStart)
// We zoom the time-range when the end-time changes.

TimeScaleType baseTimeScaleType = gantt.GanttChart.BaseTimeScaleType;
double curTimeUnits = TimeComputingUtils.ConvertTimeSpanToTimeUnits(baseTimeScaleType, curEnd - curStart);
double newTimeUnits = TimeComputingUtils.ConvertTimeSpanToTimeUnits(baseTimeScaleType, selEnd - curStart);
double curBaseUnitWidth = gantt.GanttChart.BaseTimeUnitWidth;
// Calcluate the new BaseTimeUnitWidth based on the current time units shown in the view and the current BaseTimeUnitWidth
double newBaseUnitWidth = (curTimeUnits * curBaseUnitWidth) / newTimeUnits;

// Make sure to ensure that the new value falls within the minimum and maximum.
// Note that the minimum and maximum are settable. Set values for minimum and maximum based on the time-scale headers you choose to include in the
// chart's headers and the zoom range you want to allow your end-users to zoom to.
if (newBaseUnitWidth < gantt.BaseTimeUnitWidthMinimum)
newBaseUnitWidth = gantt.BaseTimeUnitWidthMinimum;
if (newBaseUnitWidth > gantt.BaseTimeUnitWidthMaximum)
newBaseUnitWidth = gantt.BaseTimeUnitWidthMaximum;

gantt.BaseTimeUnitWidth = newBaseUnitWidth;

// The above would change the StartTime, so let us apply the starttime again:


Below is the xaml code

<reporting:Report x:Name="Report"
Title="PPL Document">

<Grid Margin="1 1 1 20">
<Rectangle Stroke="Gray" />

<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

<TextBlock Text=""
VerticalAlignment="Top" />

<TextBlock Text="{Binding CurrentPageNumber, StringFormat='Page No: {0}'}"
VerticalAlignment="Top" />

<TextBlock Grid.Row="1" VerticalAlignment="Top"
DataContext="{StaticResource info}"
Text="{Binding Now, StringFormat='DateTime: {0}'}"></TextBlock>

<!-- The DataContext for this Grid will be a gantt visual.-->
<local:PrintPageContainerGrid HorizontalAlignment="Stretch" Margin="5" Width="850" Height="900">

<Grid Margin="1 20 1 1">
<Rectangle Stroke="Black" />
<StackPanel Orientation="Horizontal"
<TextBlock Text="{Binding CurrentPageNumber, StringFormat='Page {0}'}" />
<TextBlock Text="{Binding TotalPageCount, StringFormat=' of {0}'}" />



<Grid Margin="1 20 1 1">
<Rectangle Stroke="Gray" />

<TextBlock Grid.Column="1"
Text="Copyright © 2009-2011 Omnex | All Rights Reserved"
TextAlignment="Left" />


Kindly help me to resolve this issue!,

Thank you,

Praveen Chandar Venugopal
#2 Posted : Monday, February 10, 2014 11:47:45 AM

Posts: 469


Silverlight enforces that the Print dialog is shown only from a user initiated action like Button_Click. See this thread for example:

Apparently, SL doesn't allow you to invoke Print from inside a Print_Closed handler either.

So, you will have to let your users first customize Print settings in your PPLGanttProject.PrintWindow and then again click on another "Print" button to initiate a Print.

#3 Posted : Monday, February 10, 2014 11:23:15 PM

Posts: 6

Hello ,

Good day!,

Yes i understood what you had said.But how come the printing is working when we use the same code but not trying to expand the grid ? and how come it is not working when we try to expand the grid?

Thank you,

Praveen Chandar Venugopal
Bala - RadiantQ
#4 Posted : Tuesday, February 11, 2014 10:25:16 PM

Posts: 393

Silverlight also uses an internal timer to check how long it takes to initiate a Print after the user initiated action (like button click), so when you expand, it probably takes some time (?) and that trips this internal SL timer, preventing the Print.
Tag as favorite
Forum Jump  
Please Email for any issues

ugg boots outlet cheap ugg sale ugg boots clearance ugg boots sale ugg boots cheap ugg boots for women uggs for cheap ugg shops cheap ugg boots cheap uggs Official Ugg Outlet ugg Store Buy Cheap UGGs ugg boots uk ugg boots usa ugg Online uggs on sale ugg outlets cheap ugg boot Discount UGG Boots discount uggs