Question

I'm building a Silverlight out-of-browser app that will eventually run on a Windows 7 touchscreen tablet, independent of any browser - it will run just like any other app.

My code, at the moment, is all within one XAML and corresponding .cs file but this is messy and I'd like to split it out and call each page as and when required i.e. Main.xaml, AboutUs.xaml, Contact.xaml etc.

Is this possible in an OOB app? I tried to use the frame and pages controls, but when I set the source to one of my new XAMLs via a button click i.e. "/AboutUs.xaml", it tells me that it's an invalid URI.

Thanks, Greg.

Was it helpful?

Solution

Try and create a root canvas (e.g: myCanvas) in your MainPage.xaml to act as a container which displays all your pages.

On navigation clicks, write this.

myCanvas.Children.Clear();
myCanvas.Children.Add(new myPage());

A good practice is to set a public property on every page

public MainPage parentPage;

in this case, to which you can assign the parent page that hold that root canvas (myCanvas in case). On further pages, you just navigate using

parentPage.myCanvas.Clear();
anotherPage tempPage = new anotherPage();
tempPage.parentPage = parentPage;
parentPage.myCanvas.Add(tempPage);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top