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

Foreign Key Just showing a number which is associated with the primary key
C# XNA movement not working, can't figure why
Convert mp4 to mp3 [closed]
opening a document and waiting for a user to finish editing it
Why is there no “date” shorthand of System.DateTime in C#?
Entity Framework - Why Does This Work?
Create a NHibernate Dialect that adds with(nolock) to every SELECT [duplicate]
I do not have a 'Any CPU' option present in my Configuration Manager
WCF Data Services, Entity Framework, LINQ -> Children within children
How do I determine the sender of an email via Exchange Web Services in C#?
c# fast sort and retrieve for small amount of key value pairs
MySQL Connector - removes polish characters
Project to create a book search website [closed]
C# visual control for editing statements / equations / conditions?
Generate new menus at timed intervals
Mongodb, linq driver. How to construct Contains with variable or statements

Categories

HOME
joomla
macros
salesforce
cryengine
google-docs-api
multipartform-data
sequence
dynamics-crm-2011
drush
openstack-horizon
luis
openscad
template10
powerpivot
printf
react-jsx
coccinelle
angular2-pipe
ng-tags-input
pushbullet
policy
sha
rancher
nsopenpanel
adobe-captivate
angularjs-resource
kepserverex
area
office-interop
pyexcel
definition
rexx
grails-2.0
anonymous-function
denodo
cloudconvert
multivalue
visio-2010
bioperl
node-java
cc
zedgraph
computed-properties
turbolinks
zsh-completion
glade
consolidation
universe
rowname
mate-desktop
deck.js
recurring
mod
nugetgallery
hana-sql-script
opendolphin
overlapping
angular-promise
notice
self-join
eula
vectordrawable
veeam
cl.exe
pysvn
os.walk
yosemite
cocos2d-x-2.x
redmine-plugins
im4java
fscanf
pthreads-win32
google-oauth-java-client
dylan
nokogiri
oc4j
mandelbrot
dynamic-expresso
cocotron
magicsuggest
linqdatasource
metapost
libx264
cryptarithmetic-puzzle
mail-gem
motordriver
webpage-screenshot
unordered-set
stl-algorithm
virtual-destructor
helios
konsole
scalable

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