last day (15 days later) » 

3:52 PM
1
A: How to store state in Windows 8.1 using Blank Page Template?

WPMedIt can be done with Blank Page template (although using NavigationHelper would be the prefered way). What you have to do is set NavigationCacheMode to Enabled in your Page's Constructor: this.NavigationCacheMode = NavigationCacheMode.Enabled; This way the Page with all the properties in it is ...

 
it worked as expected, but are there any issues with enabling the NavigationCacheMode?
 
It didn't cause any issues for me so far :). You can read on this topic here: msdn.microsoft.com/en-us/library/windows/apps/…
 
Thanks. Can you help me on this question also?? stackoverflow.com/questions/29565946/…
my app is crashing when I again open the same page, except back navigation.Please suggest what should I do to resolve that? And its my need to use a different page for Location.
 
It is enough if you post what you do if the navigationmode is not backnavigation!
 
In NavigationMode.New, I am getting a string object using e.parameter. toString() method. That's all. Like 'formid=e.Parameter. to string();'
 
3:52 PM
you should check if the parameter is null. Maybe it is crashing when you don't pass anything to the page.
Hey. So I guess you don't do null check
 
No the parameter is not null, but is it possible to delete the previously stored cached when NavigationMode is NavigationMode.New
 
no it's not possbile, that's why I wrote that you should initialize your variables in onNavigatedTo
but I think you should write if(NavigationMode != NavigationMode.Back)
because you can't be sure that the navigationmode is new
it can be forward
and refresh
just paste your source code here: pastebin.com
maybe there's a defect which you don't recognize
 
Ok I will paste the code but how I can share that with you from pastebin. I have never used pastebin. And the problem is its company code so I can't share a whole page code.
 
just go to pastebin.com, copy paste your source code (or part of it), and click the submit button. than copy the url and send it here
 
Ok I will share it
 
4:04 PM
ok, I'm waiting
 
Can we delete it, after solving the issue?
 
the pastebin?
 
you can set its expiration to 1 hour, and unlisted, so it wont be public, and will be deleted in 1 hour
 
Ok I have added expiration
Are you able to view the code?
 
4:09 PM
yes I can see it. What is the exception when the program crashes?
 
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
 
and where is it? line number?
 
await loadDynamicForm() line, previously it was not happening, when I added the line this.NavigationCacheMode=NavigationCacheMode.Enabled then this error started to appear
 
ok I'll figure it out
 
OK Thanks. Please let me know the issue.
I have shared the whole page code
Is there a way to delete the stored cache, then it may solve using that issue
 
4:16 PM
Ok so the problem is that you don't initialize your variables in onNavigatedTo. So I can see that you initialize the variables at declaration, but you should initialize them again if you navigate to the page newly. Create a method called for example "initializeVariables" and simply copy paste the variables you declared on top of the page, and call this method in onNavigatedTo
 
OK I will try this
 
Bacuse the navigation caching saves all the variable values. so set the variable values back to the initial state, it will work, I do the same with no problem. I initialize them
the exact variable causing your issue is _currentPageIndex . But as I said, initialize all the variables, because another may cause issues as well..
 
can you add here that part, because when i copy paste the variables declared it showing error.
 
private StorageFolder localFolder = ApplicationData.Current.LocalFolder;
private CATEGORY _dynamicFormCategory = null;
private MCSDynamicViewBuilder _dynamicFormViewBuilder = null;
private int _currentPageIndex = 0;
Dictionary<string, List<REPORTDATA>> formDataDictionary;
Dictionary<string, string> binDataDictionary;
ApplicationDataContainer userSettings = ApplicationData.Current.LocalSettings;
CancellationToken cancellationToken;
string formId = string.Empty;
string selectedGetWorkFormId = string.Empty;
these variables
of course, not declaring them again, just writing: _currentPageIndex = 0; formId = string.Empty
 
I will need to remove private keywords from there right? and what about Dictionary<string,List<ReportData>>formDataDictionary, and do I need to add _currentPageIndex and formId only?
If possible , please show me by creating a method you told.so it would be easy for me to copy paste :-)
 
4:24 PM
ok I'll try just a minute
 
thanks.
I am also checking from my side
I tried its working, but I have an image on form, but that is coming twice
 
just a sec I'll post the method soon
 
ok thanks
 
try this. I saw you have your own types, which I didn't know how to initilaize (didn't know the constructor). but I think it'll do the job
 
4:41 PM
Yes, did you checked that other question regarding maps?
I have added a link on the same question
 
i can't help in that, dude. i don't have experience in Bing maps
but does it work?
I mean, the problem which we are talking about
 
No, when I added if (formDataDictionary != null)
{
formDataDictionary.Clear();
formDataDictionary = null;
}

if (binDataDictionary != null)
{
binDataDictionary.Clear();
binDataDictionary = null;
}
if (_reportEvidenceCollection != null)
{
_reportEvidenceCollection.Clear();
_reportEvidenceCollection = null;
}
it shows null refrence exception
If I remove then, it works
 
ok than remove them ! :)
 
But, in future, these collection may have some value, then, will it cause any issue?
 
it is very, very hard to tell without knowing what these are used for, what the whole page does.
but I hope it wont. you should look up NavigationHelper for future projects
In my project I also realized too late that NavigationHelper exists, because I added blank page template
So I used this solution which I posted. It works perfectly in my case.
 
4:50 PM
Ok thanks. problem is that in reportEvidenceCollection there will be images path and name, as the page is cached, it may used the previously saved images also, which may cause issue at my side
 
than you should look why there is a nullreference exception. it is very strange because i check for null in each case
only you can debug that dude :)
Also, note that I'm a newbie in WP, I only develop in C#/Windows Phone for 4 months
 
I think, it due to while declaring variables, I have added _reportEvidenceCollection and then again _reportEvidenceCollection!=null, so at that time its getting _reportEvidenceCollection as null
 
it is not a problem. remove if (formDataDictionary != null)
{
formDataDictionary.Clear();
formDataDictionary = null;
}
and I think it will work.
because it is a dictionary which contains a List inside, which I didn't check null for
 
ok No, its still causing issue, can you check _reportEvidenceCollection in declare variables and your method?
I tried to only add that part, then also NullrefernceException is ocurring
 
5:05 PM
than I think those dictionaries you should reinitialize when you use them
so you can remove them from the initVariables method, and when you need to use them, simple add "new SomeList()" . you get it?
 
yes I will check, I am checking using count variable
 
ok dude I have to go now. I think you're in control now :) it will work, just think it over.
 
Thanks Man, it was great talking to you, _reportEvidenceCollection.Count solved the issue, thanks a lot.
 
Cool man!!! :) I'm really glad, keep it up!
 

  last day (15 days later) »