I've noticed in my programs when I have alot of complicated bindings going on then visual studio does not show the xaml properly.
Does MVVM and its numerous bindings cause this? Is the safest way to show xaml in the visual studio designer to remove bindings completely?
No. One of the MVVM core principles is designer support. The principle is called "Blendability" after the Expression Blend designer (resp Blend for Visual Studio) tool. Note, that Visual Studio uses the same designer.
With MVVM you can achieve much better design time support by databinding to design time data. For example, you in DataGrid or ListBox you can see in the designer how the actual items looks like when databound.
Breaking the designer has nothing to do with complexity of bindings.
You just need to follow few simple principles and understand what's going on in the designer.
First of all, Visual Studio designer creates instance of the ViewModel in the designer process. You need to be careful, that you don't execute such code in the viewmodel, that could break the designer. Here are some examples:
Don't do this
This will break the designer, because Visual Studio Designer is not allowed to do DB calls.
calling DB, or FileSystem in constuctor is bad practice anyway
this breaks the designer, because VS Designer does not have access to your configuration
if you databind to a property, the getter is acually executed. This code breaks the designer, because App.Current is the Visual Studio Designer, not your app! Be carefull about it.
This will cause NullReferenceException when binding to CountOfItems, because VS Designer doesn't call Load()
Good practices
Just check if you are in the design mode wherever needed:
I've created code snippet, where I use this pattern:
I don't actually instantiace the ViewModel directly, but I inject DesignTime version of the viewmodel:
If your designer breaks anyway and you don't know why, you can attach another instance of visual studio to the xaml designer process and it will nicelly show the problematic line of code.
Last, but not least, you can easily turn off instanciating the ViewModels. Just set
IsDesignTimeCreatable=false
in d:DataContextRecapitulation
Yes if your bindings and Viewmodel are complex there are chances that your design time maynot work. But if you want design time support, then create a dummy viewmodel and you can set it as design time viewmodel which will use the dummy viewmodel only for designtime. Check below code.