可以先在App.xaml后台代码中定义一个对象:
Grid rootGrid = new Grid();
同时在App.xaml后台代码中新增一个方法:
/// <summary>
/// 页面跳转
/// </summary>
/// <param name="usercontrol"></param>
public static void RedirectTo(UserControl usercontrol)
{
App app = (App)Application.Current;
app.rootGrid.Children.Clear();
app.rootGrid.Children.Add(usercontrol);
}
然后以后的Xaml页面直接通过以下方式处理:
App.RedirectTo(new MyXXXaml());
例如:
namespace SilverLight_My
{
public partial class App : Application
{
public App()
{
this.Startup += this.Application_Startup;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = rootGrid;
}
/// <summary>
/// 页面跳转
/// </summary>
/// <param name="usercontrol"></param>
public static void RedirectTo(UserControl usercontrol)
{
App app = (App)Application.Current;
app.rootGrid.Children.Clear();
app.rootGrid.Children.Add(usercontrol);
}
}
}