• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
无忧岛主
实践是检验真理的唯一标准
博客园    首页    新随笔       管理    订阅  订阅
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());

如果本文引用了你的文章而未注明,请及时联系我。
posted on 2012-10-18 16:23  无忧岛主  阅读(183)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3