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

How to copy data from Windows phone app internal storage to SD card or phone
Main thread freezes when waiting for Web service synchronously in Windows Phone Silverlight Application 8/8.1
ASP .NET GridView not displaying rows
SQL stored procedure not returning all SELECT statements
C# Calculate the image scroll with scrollbar
stream audio and video data separately
Azure Active Directory Authentication with Azure Mobile Services Failed
Xamarin Parse Component refresh current user
How to use Automapper to map an object to an interface at a different level?
ASP.Net C# equivalent to Coldfusion cfoutput GROUP
HtmlAgilityPack convert XPath query to LINQ
How to assign System.Drawing.Color to Microsoft.Office.Interop.Excel.ColorFormat
Construct a list of wpf Hyperlink elements from an XML source file using Linq
Exception while using Regex with richtextbox in C#
Is there is a way to generate “simple” url with #Url.Action?
How to get the cell index of textbox in my gridview

Categories

HOME
classification
http
macros
aix
redhawksdr
mailchimp
foreach
clip-path
coding-style
select2
mamp
captcha
xmlhttprequest
pylint
amazon-data-pipeline
powerpivot
windows-phone
android-actionbar
novacode-docx
draw2d
single-page-application
poisson
scrapy-spider
workflow-foundation
libxml2
typeclass
bytebuffer
spring-data-gemfire
r-factor
schedule
deferred
overflow
ios-autolayout
snapkit
machine-code
dom4j
azure-vm-scale-set
dotnetnuke-module
mapquest
latency
mediastream
julia-jump
qt-quick
firefox-developer-edition
python-venv
android-doze-and-standby
qtwebkit
fckeditor
programming-pearls
printer-control-language
bipartite
disassembly
cardview
firebase-polymer
consolidation
key-value-store
hfp
sbt-proguard
cexception
alchemy
firefox-os
fadein
videoview
encode
biginsights
persian
xml-simple
pdcurses
firewire
veeam
accpac
numerical-recipes
jsonmodel
grunt-contrib-connect
sync
nsurlrequest
gnip
rails-migrations
episerver-7
dateadd
fastcgi-mono-server
mongoid4
nop
mahara
grunt-wiredep
8-puzzle
mencoder
nokogiri
playing-cards
forward-declaration
gmail-imap
auctex
doxia
jquery-ui-map
inserthtml
project-files
jexcelapi
llblgen
text-manipulation
nstoolbar
chromebug
silverlight-2.0
system-analysis
mysql-pconnect
calendarextender
rpxnow

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