c#


Code in user control breaks design mode in Visual Studio 2015


I have a usercontrol that breaks design mode with a stack exception in Visual Studio 2015 when I modify pages the usercontrol is on. If I delete the bin folder/clean/recompile it briefly works again. The app itself runs fine. This code is conditionally called from the usercontrol_loaded or constructor
private async void GoBack()
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
if (((Window.Current.Content as Frame).Content as Page).GetType() == typeof(Inputs))
return;
if (((Frame)Window.Current.Content).CanGoBack)
{
foreach (PageStackEntry page in ((Frame)Window.Current.Content).BackStack)
{
if (page.SourcePageType != typeof(MainPage))
((Frame)Window.Current.Content).BackStack.Remove(page);
}
}
if (((Frame)Window.Current.Content).CanGoBack)
((Frame)Window.Current.Content).GoBack();
});
}
And I get this error:
at MainAppBar.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c__DisplayClass2.b__3(Object
state)
Any suggestions on how to fix this? It designer seems to be running this code and is confused with the navigation code? Is there a way to exclude this code at design time?
If there's any particular code that cause problem at design mode, you can skip executing the method by checking if it's in Design mode.
public static bool IsDesignMode(this object o)
{
return (bool) DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof (FrameworkElement)).Metadata.DefaultValue;
}
if (!this.IsDesignMode())
{
Task.Factory.StartNew(GoBack, ...
...
}

Related Links

Proxy GZIP Compression
Getting SQL to work from C# with Dates
Store Enum as Char with Dapper
Drag and Drop Windows Forms: Controls dissapear after dragging
What is the best way to count all instances of a single process running under a particular user logon?
C# Security Protocol Specification
Ajax Dropdownlist using cascading dropdownlist in asp.net
Adding textbox value with button in C#
How to show the tooltip without any time duration?
How can i hide in game view a ui button and show the button when pressing the escape key?
TCP Connection. best way to handle multiple connections [duplicate]
Send POST request with Image from Unity3D
How to make default Password Reset functionality work in ASP.NET Core
UriTemplate Matching Email
Error handling between web api and angular 2 client
Get Duplicates in List and Edit Item

Categories

HOME
drupal
classification
internet-explorer
oop
ssms
kendo-ui-angular2
display
abc
aix
apache-storm
azure-resource-manager
datetimepicker
opc-ua
mailchimp
glympse
powerquery
yuv
comments
scapy
restheart
token
jcodemodel
jpql
openstack-horizon
orange
printf
django-rest-auth
glibc
sonarlint
keystone
pumping-lemma
deployment-descriptor
spring-data-gemfire
key-bindings
log4net-configuration
contextmenustrip
node-soap
ilog
javafxports
console.readline
idea-plugin
fisheye
mixed-models
wicket-tester
contenteditable
wufoo
spring-webflow-2
sharpssh
richtext
blackberry
timex
msiexec
huawei
copy-constructor
mac-app-store
alfred
access-violation
disconnect
user-profile
music-player
wiql
maven-antrun-plugin
syncano
joomla3.3
dcg
polarion
euro
eula
targetprocess
vectordrawable
tinymce-plugins
tidesdk
minko
copy-on-write
veeam
autopep8
jad
mri
applinks
report-builder2.0
nsurlrequest
worklight-appcenter
fscanf
nokogiri
pyxplot
backbone-views
android-memory
google-email-audit-api
pdf-reader
datasheet
umfpack
digg
auto-compile
nbehave
lwp
fxcopcmd
rollover
activescaffold
chromebug
p4.net
pitch-shifting
dongle
versions
hp-trim
dojox.gfx
coderush-xpress
manuals
cons

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App