Just add this line in MainPage.xaml.cs page
Use the static proeprty DesignerProperties.IsInDesignTool to determine if your code is currently being used in a designer tool.
InitializeComponent();
if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
//Code that throws the exception
}