Event causes exception due to missing resource - winforms

My form has 96 check boxes, 4 DataGridView controls, and some other controls. Everything works fine until I add an event to the fourth DataGridView. When I add any event to that control, the code builder adds a resource that compiles but causes a run time exception. The exception is:
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture.
I ran a Diff between the code that works and the code that causes the exception. When I add the event to the DataGridView control, the code below is added to my MainForm.h file.
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
Each of the checkbox controls have a line as shown below that wasn't there before adding the event to the DataGridView.
resources->ApplyResources(this->checkBox_D1, L"checkBox_D1");
The code builder deleted the code below from each checkbox after adding the event.
this->checkBox_D1->AutoSize = true;
this->checkBox_D1->Location = System::Drawing::Point(30, 19);
this->checkBox_D1->Size = System::Drawing::Size(40, 17);
this->checkBox_D1->TabIndex = 0;
this->checkBox_D1->Text = L"D1";
The only difference that I can find between the fourth DataGridView and the others that don't cause the problem is that three of them are inside a Group box and the fourth one is outside the Group Box. I created all four DataGridView controls by copy and pasting from the first one. I thought that might have caused the problem so I created the fourth one from scratch, but it didn't resolve the issue. All four DataGridView controls call the same event handler and point to the same function.
I changed the name of Form1 to MainForm, but it still shows up as Form1 in some places. Why is that, and is this causing this issue?
Any suggestions would be greatly appreciated!
Thank you.

I solved this issue by recreating the form. It was faster to recreate the GUI and transfer all my code than to try to figure out how to fix it. I'm going to guess that the project got hosed up, but I don't understand how Visual Studio organizes the resources well enough.

Related

WPF UserControl throws exception in design mode

I'm trying to create a custom control using UserControl. When I drop the custom control on a window, it displays for a second then the designer crashes and I get the messag:
An Exception was thrown
ArgumentNullException: Value cannot be null.
Parameter name: sp
The stack trace shows an error in a call the ServiceProvider constructor.
Any idea what's going on on here? I tried this with a blank UserControl on a blank Window and got the same error.
Thanks for your help.
XAML designer will call the UserControl's constructor when loading in designer.
If in the constructor or UserControl.Loaded is another Method that is not running in the design mode should be skip.
In order to avoid this you can place a if condition as follows in your UserControl constructor
if(DesignerProperties.GetIsInDesignMode(this))
return;
// another Method that Running in RunTime
WPF user control throws design-time exception
After further googling the issue, it seems that this is related to the presence of installshield projects in the solution. If I remove all installshield projects, I don't get the exception anymore.
This is more of a workaround than a solution though...

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

The whole wpf application is blocked after i call Show() for new window

I am developing a WPF-application using mvvm pattern. And a strange problem occurred to me.
There is a form, which contains a devexpress DXGrid control. There is a command binded to double click gesture in presenter. When the command triggers a new window is created and shown through factory class(the Show() method is used).
So, it happens from time to time that the whole application(all application windows) is blocked when this window is shown. This lockup disappears after i focus any other application.
For the first time this problem occurred after updating devexpress version. Then this problem occurred any time new window was shown after double click on grid row. The problem was partially fixed by setting new window`s Owner property.
Now this problem occurs from time to time. It seems as if threads are involved here, but i dont understand how. =(
p.s.:
there is one more strange thing, when new window is shown and no lockup-problem occurred, the first window is still focused and i have to click on newly shown window before i can use any controls, placed on it.
I have tried:
set ShowActivated property
call Activate() after Show()
newform.Dispatcher.CheckAccess() to
determine which thread calls Show()
method
check newform.IsActive property after
show (value = true)
Could you tell me how to fix, please?
Thank you.
Well to fix the issue of first window being focused rather than the newly shown window, you need to do the following, after calling the show method for the new window:
Mouse.Capture(null);
Hopefully the issue would be resolved.

Bug in WPF DataGrid after upgrading to .NET 4.0

Situation is as follows:
A DataGrid has a RowDetailsTemplate, which contains another DataGrid (the subgrid). If you add a DataGridTemplateColumn which contains an EventHandler, a NullReferenceException is thrown by PresentationFramework.dll.
This issue is only present in .NET 4.0. If the project targets .NET 3.5 (and uses WPFToolkit for the DataGrid component), everything works as expected.
I attached a small sample project which reproduces this error. In the project is a README file which explain the issue again and shows the stacktrace of the exception.
(the sample project can be found here)
Steps to reproduce:
1. Run the sample project as is.
2. Try the 'Delete Me' link in the first line of the grid, confirm that it displays a message.
3. Click the 'SHOW' cell in the first column, and confirm that it displays a subgrid with one item.
4. Try the 'Delete me' link in the subgrid, confirm that it does nothing.(it is not wired up in code).
5. Close the window and go to MainWindow.xaml
6. Wire up the Hyperlink.Click event in MainWindow.xaml on line 36: add Click="HyperlinkClick" to the Hyperlink tag.
7. Run the project again, and click on 'SHOW' in the first column: a NullReferenceException is thrown!
This is crossposted from https://connect.microsoft.com/VisualStudio/feedback/details/603333/wpf-datagrid-rowdetails-add-2nd-datagrid-to-rowdetailstemplate-with-eventhandlers#details , but this is a blocking issue for me.
So the problem is: why is this happening? I think this is a bug in the PresentationFramework code, but I'm not 100% sure. What can I do to make the EventHandler work as expected?
I found a temporary work-around by allowing the user to press the delete-key, but this breaks the behavior of our app.
Is there anyone who can reproduce and comment on this issue?
I had a similar problem that seemed to have something to do with CanUserAddRows="True"...if I set that to false the problem goes away.

Adding a user control "The Enumerator is not valid"

I'm using Visual Studio 2010 to create a small WPF application. I've created a user control that I am now trying to add to my main form. The user control does show up in toolbox but every time I try to drag the control to the form I get the error:
The enumerator is not valid because the collection changed.
I should know what's wrong and it is bugging me that I can't figure it out.
You have a bug in the constructor of the usercontrol - you are using a foreach-loop over an IEnumerable and while the loop is running, the IEnumerable is changed, this is not allowed with a foreach loop. Use a for loop instead if you are manipulating the Collection you are iterating over.
The problem here is that you don't know what code is throwing the exception.
WPF is terrible about exceptions, especially in constructors. The framework insists on catching and re-throwing a new exception, usually multiple times, and it's difficult to find the original stack trace. I've found the easiest way to track down this kind of error is to tell Visual Studio to stop as soon as the exception is thrown, rather than waiting until WPF has re-thrown it a couple of times and made the details difficult to dig out.
I don't have Visual Studio 2010 in front of me, but here's how to do this in VS2008 -- 2010 is probably similar:
Go to the Debug menu > Exceptions...
Next to "Common Runtime Language Exceptions", check the box in the "Thrown" column
Then debug your app again. It will stop at the line that's actually causing the problem, and it'll be much easier for you to see what's going on. And if you're still not sure why it's throwing an exception, you'll be able to post a code sample.
In order for a user control to function properly you need to have a constructor that takes zero arguments. This way the form designer has a way to render the control in a "default" manner.
I then overloaded my constructor to take the arguments I needed to actually run the control properly and everything worked as expected.
You need to:
Remove the DLL reference
Add a reference to your control
Rebuild the solution
Add your control. It should work!

Resources