Silverlight 5 not printing on some printers - silverlight

I have a Silverlight 5 OOB application (with Elevated Permissions) that's just been deployed to a number of our users.
Some of these users are reporting that prints are coming out blank or very faint.
These printers do print Word documents correctly and I am unable to reproduce the problem on my own printers.
All users are on Windows XP SP3 32 bit, and I am developing on Win7 64 bit.
As anyone seen this issue before? Or any idea what could be causing this?
Help much appreciated.
Many Thanks,
Andrew

I Should Got Solution May Be useFull To You.............................
First i created a new PrintDocument, and hooked up some handlers for its PrintPage event.
mobjPrintDocument = New PrintDocument
RemoveHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
AddHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
Then we can call the PrintBitmap function on the PrintDocument whenever you want to print. Here I am doing it when the user clicks the Print button.
Private Sub xbtnPrint_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
mintPageIndex = 0
mobjPrintDocument.PrintBitmap(FileName)
End Sub
Now comes the important part. We can hijack the content targeted by hooking into the PrintPage event (as handled above). I can set the e.PageVisual to any visual xaml element and the PrintBitmap will handle it. Here I use the GetPages function and loop through to make sure I print each page (a pdfviewer element). However, you can point it to any visual element like I said.
Private Sub Print_Report(sender As System.Object, e As PrintPageEventArgs)
e.PageVisual = xobjReportViewer.GetPages(mintPageIndex)
mintPageIndex += 1
e.HasMorePages = mintPageIndex < xobjReportViewer.GetPages.Count
End Sub
The e.HasMorePages allows you to force the firing of this event until you are finished.
Hope this is helpful to someone. With Silverlight 5 and the Post-Script printer support, alot of printers that have a PostScript emulator may not be compatible, but will also not default to bitmap printing. This workaround fixes that, making printing a little bit more stable in a LOB type application.

Related

How navigate from one page to another?

Currently I am working on a xaml page with several buttons that are going to link to other xaml pages, but I cannot figure out how to navigate from one xaml page to another. This is what I currently have.
Private Sub GoTools(sender As Object, e As MouseButtonEventArgs)
MainFrame.Navigate(New Uri("Tools.xaml"))
End Sub
This is what I have seen on a lot of websites so far but this does not work, how should I change this so that when I click a Tools button it brings me to the Tools page?
(Quotes have been changed)
When I run the program and click the button I get this error
An unhandled exception of type 'System.UriFormatException' occurred in System.dll
Additional information: Invalid URI: The format of the URI could not be determined.`
How about you do it this way:
Private Sub GoTools(sender As Object, e As MouseButtonEventArgs)
MainFrame.Navigate(New Tool)
End Sub
I am not familiar with VB, but you have to create an instance of your Tool page. In case you already have one just navigate to it.

Handle exceptions in VB.net and WPF

I am having a hard time to create an exception handler in a WPF application coded in VB.net.
I already read a tons of articles on the internet, but most of them only work in WindowsForms or are written in C#.
The thing I like is a simple MessageBox with the crash reason when the application is crashing.
I think this here
should be the way to go, but I cannot get it to work, since it seems to be for Windows Forms.
Visual Studio show multiple errors, mainly because it is not finding the UnhandledException event...
I would be really grateful about an explanation how to get the think I try to get.
Edit: Something like this
You're probably looking for Application.DispatcherUnhandledException event.
In App.xaml you need to add a handler for this event:
<Application DispatcherUnhandledException="DispatcherUnhandledExceptionEventHandler" .../>
Then in code behind you can write your code for handling the exception:
Private Sub App_DispatcherUnhandledException(ByVal sender As Object, ByVal e As DispatcherUnhandledExceptionEventArgs)
' Process unhandled exception
e.Handled = True
End Sub
Here you can find more information, even with sample code in Visual Basic.

Silverlight 5 printing garbled Reports

I am using a C1ReportViewer control, and have already posted a question on the C1 forums, however i thought i would post here as well to see if anyone had run across a similar issue. The control uses the generic silverlight PrintDocument() method.
When printing a Crystal Report from this control in Silverlight 5 sometimes the report prints out garbled, meaning different sized text, tapered lines and generally out of position. It also rarely prints the entire report.
I have narrowed the issue down to a few printers, and only with machines using their 32 bit drivers. Based upon this, and the changes made to Silverlight 5, i am assuming the issue revolves around PostScript compatibility. However, as our product is LOB application, enforcing PS compatible printers and printer drivers is nearly out of the question.
Accordingly, if this is indeed a post script issue, based upon the documentation for silverlight 5, the PrintDocument() method should be failing back to the default bitmap method. See Am I correct in understanding that vector printing in SilverLight 5 will only work with a Postscript printer?
My question for stackoverflow is: Has anyone encountered a similar issue in with printing in Silverlight 5, or has anyone had success printing Crystal Reports/PDFs? And in the off chance that anyone has, what solutions have you come up with?
Much Appreciated,
Greg
I was able to come up with a solution for this. Instead of using the built in C1 Printing functionality I was able to write some code to force bitmap printing.
First i created a new PrintDocument, and hooked up some handlers for its PrintPage event.
mobjPrintDocument = New PrintDocument
RemoveHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
AddHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
Then we can call the PrintBitmap function on the PrintDocument whenever you want to print. Here I am doing it when the user clicks the Print button.
Private Sub xbtnPrint_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
mintPageIndex = 0
mobjPrintDocument.PrintBitmap(FileName)
End Sub
Now comes the important part. We can hijack the content targeted by hooking into the PrintPage event (as handled above). I can set the e.PageVisual to any visual xaml element and the PrintBitmap will handle it. Here I use the GetPages function and loop through to make sure I print each page (a pdfviewer element). However, you can point it to any visual element like I said.
Private Sub Print_Report(sender As System.Object, e As PrintPageEventArgs)
e.PageVisual = xobjReportViewer.GetPages(mintPageIndex)
mintPageIndex += 1
e.HasMorePages = mintPageIndex < xobjReportViewer.GetPages.Count
End Sub
The e.HasMorePages allows you to force the firing of this event until you are finished.
Hope this is helpful to someone. With Silverlight 5 and the Post-Script printer support, alot of printers that have a PostScript emulator may not be compatible, but will also not default to bitmap printing. This workaround fixes that, making printing a little bit more stable in a LOB type application.

Blacklight Expander problem while expanding programmatically

I am doing a silverlight project in Silverlight 4 and I included the BlackLight project in my project so that I could use their new controls, especialy the dockpanel and the autoexpander, which is causing me at the moment some little problems.
What I would like to do is to have several auto-expander that will expand or collapsed when I click on button. In my case more specifically, each auto-expander have a set of parameter to fill, which in turn will fill the other expander and the current one would collaps and the just filled one would expand.
The idea is simple, yet when I use a button which is on one of my expander, it only works once... It would expand/collapse the first time, then after that, nothing. I trace the code and it seems to go through just fine, but the property value won't change
Here is my code
Private Sub BtnExpand_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnExpand.Click
ClientExpander.IsExpanded = False
ProjetExpander.IsExpanded = True
End Sub
Could it be a known bug, or must I reset some flags to make it work?
Edit : Forgot to mention, if it makes any difference, but the IsExpanded property seems to be a dependancy property.
Thanks.

AccessViolation exception when form with AxWindowsMediaPlayer closed

I have a AxWMPLib.AxWindowsMediaPlayer on a form. When I close the form, I get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." exception. It is OK with hiding the form but not with closing. Everything's fine when the component is removed from the form.
This is Winforms .Net3.5.
Any help appreciated.
This was happening to me, and it was when closing the form during a key press.
Seems the WMP control will cause problems if it has a key event to process.
Example with Form.KeyPreview = True
Sub Form_KeyDown(e As KeyEventArgs)
AxWindowsMediaPlayer1.Dispose()
End Sub
Causes an Access Violation.
Sub Form_KeyDown(e As KeyEventArgs)
e.Handled = True
AxWindowsMediaPlayer1.Dispose()
End Sub
Closes cleanly, as the key press is blocked from reaching the WMP control.
Same thing happens when the form is closed as will dispose of the control.
Sometimes when working with ActiveX objects in .NET applications it is necessary to force garbage collection on exit. I generally do this in Form_Closing using:
GC.WaitForPendingFinalizers()
GC.Collect()
Also, if you have setup any event handlers for the object, you will want to disconnect them explicitly. I've found on a number of occasions that ActiveX objects will still remain active in the garbage bin and will attempt to call the event handler even after they have been disposed.
It may also be worth it to make sure playback has stopped before you try to dispose of the object.
ActiveX objects may have some sensitive dependencies on being closed in the correct order when the parent form is closed, otherwise they may go on living until gc runs - try looking through the interface for the control for any methods that look like they may have to do with closing, or destroying the object and calling those.
I think I have it:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
axWindowsMediaPlayer1.close();
}
simply found the method on the doc http://msdn.microsoft.com/en-us/library/windows/desktop/dd562388(v=vs.85).aspx
I thought I'd give it a go. it seems much better now.

Resources