wpf binging throws argumentnullexception
How do you handle when the editor (xaml / design) in visual studio throws an argumentnullexception, "value cannot be null" ?
I am reading some values from the database using entity framework and storing them in an observable collection so开发者_如何学编程 I can bind to them from xaml. It is logic to suppose that there might not be any values in the collection so the exception is correct, right? Even if I have values in the database, the exception is still thrown because the editor (when viewing in design mode) is not running the application to get the values, which is still normal.
When I run the application, everything works fine but the exception is very annoying.
I also get an error, using a try catch when reading from the database, but only in editor (xaml) not when running the application, that says "The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. The stacktrace gets me into the entity data model itself. I am using mysql as a backend. This messagebox with the error is thrown everytime I type something (a character) in xaml !
My unit and integration tests all work fine.
Btw is this normal ?
EDIT: If I add the initialization of the viewmodel in the app resources (in app.xaml.cs but not in the app.xaml) it seems to work. I don't see the errors when I write the code in xaml or when I switch to design to see how it looks.
You can design some sample data for the design mode so that you can see the designer and write code in xaml without any designer exception. For this, you might need to use DesignerProperties class (e.g DesignerProperties.GetIsInDesignMode(this)
etc). I have faced similar XAML designer crush and solved using this technique. I would recommend reading this guideline for further assistance.
You can debug the designer :-)
For this make a breakpoint in your model (at the beginning)
now in the project options under "Debug" chooose "start with external program" ans select the devenv.exe
now when you run your project, a new visual studio instance will appear. When you open your window in the new visual studio instance, the break should be hit in the first instance of visual studio
精彩评论