I'm trying to achieve navigation like layout using UserControl created by user.
I have a Silverlight Page that loads Usercontrol by setting the Content to a Frame Element.
UserControl1 uc1 = new UserControl1(); this.Frame.Content = uc1;
Similarly I have a Frame in each UserControl where the content is set to a Frame.
This works well and good.
Problem: I have the current situation
|UserControl1 | UserControl2 | UserControl3
--------------------------------------------------------------------------
UserControl1 |   | CHILD |
UserControl2 | PARENT | |CHILD
UserControl3 | |PARENT |
So now what I'm trying to achieve is that when the user opens UserControl2 from UserControl1, i need to be able to move back from UserControl2 to the parent(UserControl1) in the same state it was before.
Is this actually possible? If yes then what should be done? Any Hints, code, Article references are appreciated...
Reason:
I'm trying to avoid passing variables in page query and use usercontrols.
Scenario:
For instance if the user wrote "Hello World" in a Textbox inside UserControl1 and presses a button,load UserControl2. After he presses OK in UserControl2 go back to UserControl1 with the Textbox still showing "Hello World"
Hope I'm clear. Let me know if any clarification is needed.
Cheers
Answer: 1
Yes this is possible, but your controls should not be UserControls, but instead inherit from Page and you should use the Navigate method of the Frame to set the first page
this.Frame.Navigate(new Uri("Page1.xaml", UriKind.Relative));
Then to navigate from page 1 to page 2 use the NavigationService of the Page
NavigationService.Navigate(new Uri("Page2.xaml", UriKind.Relative));
by : Shawn Kendrothttp://stackoverflow.com/users/1054961Answer: 2
Here's an example of how you might do it:
List<UserControl> navigationStack = new List<UserControl>(); public void NavigateTo(UserControl newUC) { // when navigating to a new control, keep the old one in memory if (this.Frame.Content != null) navigationStack.Add(this.Frame.Content as UserControl); this.Frame.Content = newUC; } public void NavigateBack() { // when navigating back to an old control in memory, // retrieve it off the navigation stack UserControl oldUC = navigationStack.LastOrDefault(); if (oldUC != null) { navigationStack.Remove(oldUC); this.Frame.Content = oldUC; } }
by : Chui Teyhttp://stackoverflow.com/users/34461
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog