silverlight窗体的跳转和页面的跳转
silverlight中页面的跳转有点麻烦,需要修改app.xaml中的方法。
第一步:添加全局变量:Grid rootgrid=new Grid();
第二步:修改Application_Startup方法改为
this.rootVisual=rootgrid;
rootgird.Children.add(new MainPage());
第三步:写一个方法如下
public void RedirectTo(UserControl usercontrol)
{
App app = (App)Application.Current;
app.rootGrid.Children.Clear();
app.rootGrid.Children.Add(usercontrol);
}
第四步:建立两个页面page1.xaml和page2.xaml在page1.xaml上加一个button
双击后写方法:
App app = (App)Application.Current;
app.RedirectTo(new page2());
如果链接default.aspx页面则需要使用
HtmlWindow html = HtmlPage.Window;
html.Navigate(new Uri("default.aspx",UriKind.Relative));