[Q] NavigationService and form controls

adamrob69

Member
Jul 28, 2009
45
0
0
I have a main form with a load of controls on it. I have a listbox, and a piece of code that is looking at individual items eg:

Code:
dim listitem as listboxitem = me.listbox.item(0)
when i use the navigationservice.navigate function to navigate to a different page, and then navigate back to the main page i can no longer edit that list box. The code still runs and doesnt error, but the list item is not updating. Its almost like there are two instances of the form open.

Any ideas?:confused:

thanks
 

adamrob69

Member
Jul 28, 2009
45
0
0
when im navigating back to the main form i am using another navigationservice.navigate. Im guesing this is creating a new form everytime you use the .navigate as when i use navigationservice.goback from the second form it works fine.

To that end, is there a way you can close a form once you have navigated away from it using .navigate? and can you navigate to an already open form (without creating a new instance) and without using .goforward?

thanks (im using vb silverlight by the way)
 

sensboston

Recognized Developer
Nov 18, 2009
2,142
797
193
Boston, MA
... i can no longer edit that list box. The code still runs and doesnt error, but the list item is not updating. Its almost like there are two instances of the form open.
Hmm... Could you explain what do you mean? How do you "edit" list box? :rolleyes:
Post your code and explain what are you trying to do.

P.S. Have you tried to trace your code with breakpoints on the page constructors? Just try - you will be very surprised :D
 

adamrob69

Member
Jul 28, 2009
45
0
0
Code:
''MainForm

sub EditListBox()
dim listitem as listboxitem = me.listbox.item(0)

listitem.content = "New List Text"
end sub

sub Navigate()
   NavigationService.Navigate(new uri("/Page2.xml",relative))
end sub
Code:
''Form 2

sub NavigateBack()
   NavigationService.Navigate(new uri("/MainForm.xml",relative))
end sub
The EditListBox() routine is called every x mins from a system timer. When navigated to form2 then back again the code still runs, i can put a break in and can see it running through the code but the listbox isn't updating. I believe this is because when you use the NavigationService.Navigate function it creates a new instance of the page. On form2 if I use NavigationSevice.GoBack instead of .navigate the main form updates the listbox correctly.

So if that is the case; is there a way you can close a form once you have navigated away from it using NavigationService.navigate? and can you navigate to an already open form (without creating a new instance) and without using .goforward?
 

sensboston

Recognized Developer
Nov 18, 2009
2,142
797
193
Boston, MA
I've already gave you a hint (to debug constructors). Yes, if you are using NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); or NavigationService.Source = new Uri("/MainPage.xaml", UriKind.Relative); it creates a new page.
This implementation have a sense if you start thinking in web-based terms (what is Silverlight built for!)

BTW, I don't understand your requirements. Why do you need this? What's wrong with GoBack() or GoForward()? Also, have you tried other WP7 layouts (Panorama etc.)?

Try to follow the MS "Metro UI" recommendations and many questions will disappear shortly... :)
 

williammel

Senior Member
Nov 27, 2010
66
3
0
GoFoward won't work:
http://msdn.microsoft.com/en-us/lib...ation.navigationservice.goforward(VS.92).aspx

It seems like your problem isn't navigation, (because you should be using GoBack) but that the previous page that you GoBack to isn't how you wanted it.

If this is the case, you should add some sort of way to tell an event occurred. For example, if you did (note this is really rough)


Page2.xaml.cs
{
...
public static bool VisitedPage = false;
...
}

and when you visit the page, simply set it to true.

Then, when you GoBack, in OnNavigatedTo

protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (Page2.VisitedPage)
{
//process why you needed to go tot he page
//clear the page for a fresh run
}
}
 

d1k_is

Senior Member
Apr 28, 2009
215
7
0
Brisbane
dkdevelopment.net
Have you tried unselecting that listbox item when you goback?

I had this same issue not too long ago where since it was the same instance of the page the listbox item was still selected when I returned and since the event on the listbox is "selectedchanged" it doesnt change when you select the same 1.
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone