Strange rendering error in SL app... out of browser issue? - silverlight

I've been working on a SL5 app for a few days. I've mostly been using a hard coded dummy data collection when styling my app's view. Everything has been working fine, but now I want to connect it to a dynamic data collection generated by my view model (using the data service technique where you have design time & real data depending on the IsInDesignTool property.
After I cleared out the control of the hard coded data and bound it to a collection in my view model. When I run it in debug mode, I see an unhandled exception being thrown in App.xaml.cs. The exception args don't say exactly what the problem is (it is simply saying "Value does not fall within the expected range" but when I look at the sender I find the following coming from the MainWindow (my app only has a single view): "Out-of-browser specific settings do not affect in-browser applications."
Further, when I try to view the MainWindow in the designer in VS, it doesn't render and instead shows an error (the rendered exception in the designer doesn't have any of my namespaces in it, just things about controls & UIElements).
I'm at a bit of a loss how to troubleshoot this. I didn't set anything for out-of-browser when building the app and since it worked with dummy data collections, why would it suddenly have this issue (seems like if I was using an out-of-browser property it would have shown up before I bound the data to the view).
Tips/pointers?

(sorry for my bad english)
I am not sure on what is happening but I saw the error "Out-of-browser specific..." when I tried to access some specific property only available to OOB while running on browser. The solution was to test if running oob before using the property:
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.MainWindow.WindowState = WindowState.Maximized;
}
The other problem possibly is unrelated - and sometimes can be really hard to debug - one thing that helped me is to open another instance of VS and attach it to the one where you are seeing the problem. With this setup, go to your problematic View and change to "design view" - keep an eye on the Output window of the attached VS to see if some meaningful exception is shown.

I had a similar issue.
I did put a Textbox inside kind of Listbox (radPanelBar) and added
HorizontalScrollBarVisibility="Auto" to the Textbox. It seems that the textbox had problems when to show the scrollbar and when not. Adding
ScrollViewer.HorizontalScrollBarVisibility="Disabled" to the Listbox did solve it ( so, no OOB issue at all ).

I'm not entirely sure what the error was, but it wasn't at all realted to OOB. I'm using a data service approach (in design time I programatically build real data, not the Expression Blend sample data, but when not in a design tool, it uses the REST services). I started disabling a lot of things in my dynamic data and slowly added them back. Somewhere along the way my dummy data generation was fouling things up, but SL thought it was an OOB issue.

Related

Error while loading designer in wpf form

My application is working fine, all of a sudden while loading a designer in wpf form, im getting errors.
Object reference not set to instance of an object.
As if it is in a loop. After pressing the enter button for sometime. Im getting this error.
Microsoft Visual Studio XAML UI Designer has stopped working.
And after this, im getting this.
System.Runtime.Remoting.RemotingException
[9980] Designer process terminated unexpectedly!
The number in square brackets is changing evrytime.
Im using Visual Studio 2012. Im not yet running the application, Im just switching to designer mode from code behind. If I compile and run the application, it runs fine.
Kindly help.
Edit:
Here are the three errors in single image. (I cant post morethan one link)
xamlerrors
There's an error either in the code-behind or DataContext (if you're using a ViewModel). After you fix that error, click on Click here to reload the designer. What's happening is that the designer is trying to load everything up during design time and since there's an error, it's unable to, as if the program was actually running. That null reference exception can be a bit misleading in terms of trying to figure out the cause, because it'll be thrown if you have an error in your code-behind or ViewModel.
Things to check:
Is your View referencing the correct ViewModel?
Is your code-behind portion of the View matching the View name? Some people copy their Views, but forget to change the Class name in the code-behind.
Do you have any errors in your ViewModel?
What about models? If they're loaded during design time and contain errors, this could cause the above exception.
I noticed that those kind of errors are almost everytime caused by
an error in the parameterless constructor of the view
an error in the constructor of the view model which is attached to the view
Keep in mind that when the designer loads, it calls the parameterless constructor of the view (there has to be one for the designer!). If there are "complex things" done there which can only performed correctly at runtime, there will likely be errors at design time.
The same is true for the constructor of the view model which is called from the view.
Check whether design mode is active
For example you should not load data from a repository in a constructor.
If you do it in the constructor, at least check whether the design mode is active or not like explained in this answer here about the GetIsInDesignMode attached property and only do the complex logic in the constructor if the design mode is not active.
Debugging the problem
You also have the possiblity to debug the problem. In order to do this, you have to open a second instance of Visual Studio and debug the designer process of your original Visual Studio instance from there.
The process is described in detail here: Debugging an Exception (only) occurring in design view

Exceptions in WPF Word Addin are not being handled

I am creating a WPF Office add in, and I would like to handle all exceptions in one place. To do this I use the following code in the constructor of my MainWindowViewModel:
Dispatcher.CurrentDispatcher.UnhandledExceptionFilter += new
DispatcherUnhandledExceptionFilterEventHandler(HandleAllException);
In my test environment I host the WPF app from a console application project, and exceptions are handled as expected. When I host the WPF app from within word however, nothing happens when exceptions are thrown. There is no notification at all that there has even been an exception, other than in the output window in visual studio. Does anyone have any suggestions as to what I might be doing wrong?
I have solved the problem by changing the way in which I launch my WPF app. I believe the problem was related to this.

DevExpress PivotGrid (Silverlight) : Popup Menus don't popup

We are using DevExpress Silverlight PivotGrid (11.2.7). The problem is that none of the popups work as one would expect.
Here is the xaml code (note that all of these properties are True by default and don't need to be set)
<dxpg:PivotGridControl
x:Name="pivotGrid"
... data bindings ...
IsFieldValuePopupMenuEnabled="True"
IsHeaderMenuEnabled="True"
IsHeaderAreaMenuEnabled="True"
/>
Once the host control for the grid is shown and the data is loaded right-clicking on any of the relevant areas doesn't bring either of the popups (there are 3).
Strangely (or not so strangely) in the sample SL project provided by devex everything works as it should.
The one (significant) difference between the sample app and our project is that we are using MEF and relevant .xaps are loaded dynamically based on which user logged in and some other stuff.
We have tried a lot stuff to figure out what is wrong but haven't managed to find anything even remotely relevant. Here is what we have tried :
Adding the pivotgrid to the host tabpage in codebehind after imports have been satisfied;
Setting / resetting properties mentioned above after imports from codebehind;
Adding the control to the startup page of the project before the MEF madness kicks in;
We also tried to popup the menus manually by inheriting from the pivotgrid control, but that has not yielded much;
Enabled RedrawRegions to make sure the popup is not popping 'under'. It's not;
Any pointers or ideas would be greatly appreciated.
Regards,
Alex
It appears that this was some bug in the version we were using at the time.
After updating to 12.1 everything works like it should without any tinkering from our side.
Looks like devex guys have bugs too...who knew right :)

Add / Remove Buttons disabled on a dataform

Bear with me, this is possibly a very specific problem we've encountered here:
We have a silverlight application that gets its data from a WCF (not RIA) back end service. We are displaying a collection of addresses in a dataform for the program user to edit, add to, or remove addresses from the collection.
The Addresses are bound to the Dataform as an observable collection, and the AddressView class (partial class via WCF), has been extended to implement the IEditiableObject interface.
The problem we are having is that the add/remove buttons are disabled on the control. The kicker is that this was working previously, but seems to have stopped at some point while squashing bugs and refactoring, and we haven't been able locate any related code changes.
Looking into the actual code of the dataform, the add/remove buttons are always disabled because the control attempts to cast it's internal collection to an IEditiableCollectionView, which fails, and I'm not sure why.
Any leads or pointers to try is greatly appreciated.
Found the issue to the problem. The assembly version for System.Windows.Data was incorrectly pointing to the SL 3 version. When this was changed to the SL4 version, everything began to work properly again. There's a lesson in this: when in doubt, check your references!

WPF Designer ONLY: NullReferenceException when loading connection string from app.config

Please help, for the sake of my non-pulled out hair...
The following code line:
this._connectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
is causing me untold amounts of grief.
It is in a user control, currently in the control's Loaded event but I've also tried the constructor and just plain initializing the field to the value when it's declared. Whenever I do so, the WPF designer pitches a fit on any screen that uses said user control.
The code itself compiles fine, and runs with no issues. But it's turning into a real hampering in development not being able to use the designer at all. Does anyone have any clue what could cause this and a hint as to a good practice to avoid it in the future? I suspect it has something to do with trying to access the ConfigurationManager but I can't figure out where to put the line to make it stop.
Thanks.
PS: Visual Studio 2010 Premium
When you're working in design time, you should avoid loading this. Fill in the value with some other, appropriate default, instead:
if (DesignerProperties.GetIsInDesignMode(this))
this._connectionString = "Default";
else
{
this._connectionString = ConfigurationManager
.ConnectionStrings["SqlConnectionString"]
.ConnectionString;
}
The designer probably isn't looking at your app's configuration but rather at the configuration of its current host app (VS), and so ConfigurationManager.ConnectionStrings["SqlConnectionString"] returns null at design-time.
This restriction is similar to what is see in MVC applications whereby the Web.Config doesn't get instantiated at design time. Lo...WPF does the same thing whereby the App.Config is not present at design time.

Resources