silverlight导航总结<一>应用传统的批改容器的Content或者是Child等内容来实现导航

参考文章:http://www.mysjtu.com/page/M0/S590/590938.html

第一种方法:修改容器的根元素

此方法常用于同页面栏目导航,举例:

.xaml页

<Grid x:Name="LayoutRoot"></Grid>
.cs页
LayoutRoot.Children.Clear();
LayoutRoot.Children.Add(
new Page());
导航(添加)新页或新控件之前必须清空根元素的子元素,不然根元素的子控件或页还存在。
第二种方法:修改RootVisual
此方法常用于页面间导航,举例:
App.cs
public Grid rootGrid = new Grid();

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            UserControl startpage = new nav1();
            this.RootVisual = rootGrid;
            rootGrid.Children.Add(startpage);

        }
nav1.xaml
<Grid x:Name="LayoutRoot" Background="White">
        <Button Content="跳转" Width="100" Height="40" Click="Button_Click"></Button>
    </Grid>
nav1.cs
 App app =(App)App.Current;
 app.rootGrid.Children.Clear();
 app.rootGrid.Children.Add(new MainPage());

如果本文引用了你的文章而未注明,请及时联系我。
原文地址:https://www.cnblogs.com/sunxi/p/2729703.html