Mike's Picture Mike Uttech
Adventures in Life

Interesting technique for navigating between XAML files

May 9, 2008 11:50 PM by Mike

I was looking for a way to seperate out different "pages" within a Silverlight app, and stumbled upon a method to do just that at:

http://www.flawlesscode.com/post/2008/03/Silverlight-2-Navigating-Between-Xaml-Pages.aspx

It's a pretty simple, yet effective, concept.  On Application_Startup instead of setting the RootVisual to a new instance of Page, you set it to a new Grid control, and add a new Page as a child control of the Grid. 

In my case, I wanted to maintain a UI XAML that contains my elements that need to be repeated on each "page" (master page type XAML?)  To do so, I simply added another child control (my "page" XAML) and then I don't remove the initial Page reference from the RootVisual controls.

root = Application.Current.RootVisual as Grid;

UserControl oldPage = root.Children[0] as UserControl;root.Children.Add(

new Home());

//root.Children.Remove(oldPage); // This is where I don't unload the "oldPage" which in my case is my repeatable UI XAML.


Tags: ,
Categories: Work
Actions: Permalink | Comments (0) |

Related posts

Add comment


 

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 24. 2008 1:18 PM