WPF PrintVisual - Selecting XPS in print dialog causing errors - wpf

I've spent some time searching for related topics on this, but haven't found any...
My problem is that I am getting a few errors when trying to select the Print to Microsoft XPS Document Error.
If I choose Print, I'll get the Save dialog. If I select a file and hit OK, it'll properly save my XPS file, but I noticed my WPF window turns all white, like it crashed. When trying to open up the XPS file from explorer, the content is correct.
If I choose Print, and then hit Cancel on the Save dialog, I'll get "Win32 error: The data area passed to a system call is too small".
The code I am doing is
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(this.myStackPanel, string.Empty);
}
I have seen other posts about writing much more in depth printing code, but right now this all the code is doing (I inherited this from another developer). Does anyone have a fix for this issue? Thanks.

Related

WinForms - Can't add picture to picturebox

I pretty much just started using Windows forms and I'm trying to add a picture to a picture box. First I tried the most obvious way, that is - clicking on the little arrow in the top right corner of a picturebox and clicking "choose image" in the small dialog box, but no matter what I do, the "choose image" button does utterly nothing. I know it should open some dialog box where I could choose my picture, but litterally nothing happens, not even an error message pops up.
Next I tried importing the picture through the properties of the picturebox, but after clicking on the three dots next to the image property an error message pops up, saying "value cannot be NULL, Name o parameter: docData".
I tried following this answer (How to attach a resource (an image for example) with the exe file?) and going to the properties of my project and then to the resources tab, but I have this tab completely empty, saying just that my project does not contain any default resources and a "click to create them" button. However when I click it, another error message appears saying "system cannot find the file. Exception based on value HRESULT:0x80070002"
I guess the problem must be somewhere in my resources file (which might be missing or whatever), but I have a default .resx file there that I haven't touched since the creation of this project which I had thought should be fine.
Afterall I pretty much just started with WinForms and I don't have much clue what's going on and this is quite a significant setback for me. I would be grateful for any help.

WPF ShowDialog always crash point?

I have a main window which has some menu buttons leading off onto other WPF windows.
I'm having a problem with the code behind the WPF when it crashes.
VS debugger is always showing the crash coming from my 'form.ShowDialog()' instead of the code thats actually creating the crash.
See image.
From the output I can tell its me trying to read one of my SQL database entries which is null.
My question, why does the debugger show this position form.ShowDialog() and not the actual code that broke eg
j.Status = Convert.ToInt32(reader["Status"]);
You can pinpoint easier why the dialog fails by looking at the initialization. In the dialog you are trying to display with ShowDialog(), change the code behind constructor and add a try catch. The dialog encounters an exception and cannot succesfully complete InitializeComponent() e.g:
try {
InitializeComponent();
}
catch (Exception err) {
Debug.Writeline(err);
}
Inspect why the dialog cannot initialize with a breakpoint in the catch clause.

How to make the Windows OSK open when a TextBox gets focus, instead of requiring users to tap a keyboard icon?

We are working on a WPF application in .NET 4 that will be used with a touch screen. We are trying to use the built-in Windows OSK for our input, and the last remaining issue is to get the keyboard to open up as soon as a text box gets focus. Currently, if a text box gets focus, a small keyboard icon appears (this is the InputPanel icon) and the user has to tap that icon to make the keyboard open up.
Is there a way to skip the icon step, and just have the keyboard open up all the way on focus? Preferably something that can be set or coded in one place and apply to all text boxes globally? It also needs to use the current culture settings of the application thread (which it already appears to be doing).
I haven't been able to find anything in the control panel settings that lets you skip the icon step. I also found some examples online of using the TextInputPanel.CurrentInPlaceState, but when I implemented code to open up a TextInputPanel on preview focus of the main window, I kept getting COM INTEROP exceptions and basically hit a dead end (the Microsoft.Ink.dll is an interop DLL).
Is it possible that there is a registry key that can change the default CurrentInPlaceState to Expanded instead of HoverTarget? I haven't been able to find one in my net searching.
Thanks,
Valerie
EDIT: Here is some code that I put in the main window's code behind, as well as the exception message I keep getting - and I have no idea what it means or how to fix it (my net searches failed me!)
protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base.OnPreviewGotKeyboardFocus(e);
TextBox textbox = e.NewFocus as TextBox;
TextBox oldTextbox = e.OldFocus as TextBox;
if (oldTextbox != null && boxesToInputs.ContainsKey(oldTextbox))
{
TextInputPanel oldPanel = boxesToInputs[oldTextbox];
oldPanel.Dispose();
boxesToInputs.Remove(oldTextbox);
}
if (textbox != null)
{
// Make sure we've cleaned up old panels, just in case
if (boxesToInputs.ContainsKey(textbox))
{
boxesToInputs[textbox].Dispose();
boxesToInputs.Remove(textbox);
}
TextInputPanel newPanel = new TextInputPanel(((HwndSource)PresentationSource.FromDependencyObject(textbox)).Handle);
newPanel.DefaultInPlaceState = InPlaceState.Expanded;
newPanel.DefaultInputArea = PanelInputArea.Keyboard;
boxesToInputs[textbox] = newPanel;
}
}
And here is the exception message, which occurs when my code calls the TextInputPanel constructor:
Retrieving the COM class factory for component with CLSID {F9B189D7-228B-4F2B-8650-B97F59E02C8C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
I verified that the platform target of the WPF app is x86. I ran Dependency Walker and it said that the Microsoft.Ink.dll I was using was 64 bit, and that two delay-loaded dependencies were missing (GPSVC.dll and IESHIMS.dll). I found a 32 bit version of Microsoft.Ink.dll, but I am still getting the same error, and Dependency Walker is saying the same thing - GPSVC.dll and IESHIMS.dll are missing.
I can't target x64, and I'd prefer not to have to put the missing DLLs into my application folder (if that would work?). I hope there is something simple I am missing, because this is a lot of trouble to just get rid of a keyboard hint...
Any help is greatly appreciated - I am a bit of a newb when it comes to working with unmanaged/interop assemblies...
I researched for a similar propose. In my case it was to create a custom OSK. It seems that (by now) it's not possible to create a custom input device. The explanation is in this link:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a813a08a-7960-45fe-bc91-e81cdb75bd10
Moreover, I found a "workaround" which uses Win32 API calls to access SendKey method, and report input independently of the target. The project that I found is:
http://wosk.codeplex.com/
SendKey is also available on WinForms (see http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx ) but I'm not sure if it will produce the same behavior.
I'll checking these options in the following days, but perhaps some of this information might help.
Regards
Herber

Error while printing in WPF

I'm Getting the following error while printing in WPF.
PrintTicket provider failed to retrieve PrintCapabilities. Win32
error.
Here is my Code to Print
printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing.");
I don't know what is exactly the problem, but something related to Printer.
From Control Panel -> Printers & Fax
Right Click the Printer and take Printer preferences
Change the Source property to 'Manual Feed'& Apply.(Initially it was'AutoSelect')
Still got some error.
Again me changed the Source property back to 'Auto Select'& Apply.
Changed the Quick set Property to 'Defaults'& Apply
Now its Working Fine

VS2005 Winforms Designer Exception Screen and IE8

It seems since I installed Internet Explorer V8 that my Winforms Designer Exception screen (WSOD) is broken. Where before I would get red text with the error described, today I get this:
WSOD Broken http://faxt.com/images/WSODBroken.png
Can anyone suggest to me a way to recover the text view of this display, I'm wasting time trying to read the reason the Winform file won't display in the designer now.
Thank-you.
I was able to fix this by adding a new subkey to the registry for .tmp and copying settings from .html. After these changes have been made, designer errors in Visual Studio should be rendered instead of displaying the HTML code for the error.
Open HKEY_LOCAL_MACHINE\SOFTWARE\Classes and add a new subkey of type .tmp.
Change the data of the (Default) value to: htmlfile
Add a new string value of Content Type with data of text/html
Add a new string value of PerceivedType with data of text
(source: lazypenguin.com)
The problem with that fix (adding a subkey) is that now all tmp files are treated as HTML files. I found that if you are getting it trying to download the tmp file (instead of just displaying it incorrectly), the best fix is to remove the .tmp entry from the registry (and tmp_auto_file) at "HKEY_LOCAL_MACHINE\SOFTWARE\Classes" or "HKEY_CLASSES_ROOT" as they are actually the same place. It may, however, still display as text instead of a web page.
The problem actually is "The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again. "
So I've moved Form1 class in the beginning of the file (I've created several classes before it manually) - it works! Don't do anything with IE.

Resources