set the silverlight start page
How do I set the Startup page in Silverl开发者_开发技巧ight? Not sure if am googling for the wrong terminology or it just does not seem to be mentioned anywhere.
Cheers
The term "Startup page" is somewhat ambiguous. Inside a Silverlight application you probably mean one of a few things.
The initial UserControl to load as the RootVisual
In app.xaml.cs you will find code like :-
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
}
Where MainPage
is the user control that is the initial root visual. You can change this is your own choice.
Perhaps though you want to set the RootVisual
to one of a number of possible choices. In which case you would need to use InitParams
. Something like:-
private void Application_Startup(object sender, StartupEventArgs e)
{
Type t = Type.GetType("SilverlightApplication1." + e.InitParams["StartupPage"]);
this.RootVisual = Activator.CreateInstance(t);
}
You then need to include the InitParams value in the <object>
tag in the host HTML:-
<object ...>
...
<param name="InitParams" value="StartupPage=Page1" />
</object
Use the navigation framework
Another approach would be needed if you building a navigation application. In this case the MainPage
will contain a Frame
with a Source
proeperty that would contain the initial URL to map.
With this type application you could specify alternative pages to load by simply adding a path following the # in the url of the page.
精彩评论