您的位置:首页 > 其它

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

2012-10-18 16:23 344 查看
参考文章: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());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: