(转)windows phone 7 用户控件页面跳转
2012-02-25 08:55
369 查看
原文地址:
/article/5462078.html
做项目时遇到一个产品分类展示的页面,于是用Pivot来实现,因为每个PivotItem现实的列表模板是一样的,所以就创建了一个用户控件封装一个案例列表,,Pivot页面引用用户控件时传输对应数值得到不同类别的数据.做到这里都没问题,但做案例详细页面时问题出现了.用户控件页面不支持NavigationService.Navigate(new Uri("/Views/CaseInfo.xaml", UriKind.Relative)); 哎,这怎么办呢.网上搜索资料发现原理是这样来解决的 (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/CaseInfo.xaml?id=" + curCity.id, UriKind.Relative)); 呵呵,搞定.下面是页面和代码
1.创建用户控件
用户控件.cs页面代码
2.Pivot(案例分类展示页面)
Pivot(案例分类展示页面).cs页面代码
最终效果图:
/article/5462078.html
做项目时遇到一个产品分类展示的页面,于是用Pivot来实现,因为每个PivotItem现实的列表模板是一样的,所以就创建了一个用户控件封装一个案例列表,,Pivot页面引用用户控件时传输对应数值得到不同类别的数据.做到这里都没问题,但做案例详细页面时问题出现了.用户控件页面不支持NavigationService.Navigate(new Uri("/Views/CaseInfo.xaml", UriKind.Relative)); 哎,这怎么办呢.网上搜索资料发现原理是这样来解决的 (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/CaseInfo.xaml?id=" + curCity.id, UriKind.Relative)); 呵呵,搞定.下面是页面和代码
1.创建用户控件
<UserControl.Resources> <DataTemplate x:Key="caseTemplate"> <StackPanel Width="436" Orientation="Horizontal" Height="124"> <StackPanel Width="160"> <Image Source="{Binding ImageUri}" Width="150" Height="94" HorizontalAlignment="Left" VerticalAlignment="Top" /> </StackPanel> <StackPanel Width="285"> <TextBlock Text="{Binding title}" FontWeight="Bold" FontSize="24"/> <TextBlock Text="{Binding Type}" FontWeight="Bold" Height="69" TextWrapping="Wrap"/> </StackPanel> <TextBlock Text="{Binding id}" Foreground="#FF140303" Visibility="Collapsed"/> </StackPanel> </DataTemplate> </UserControl.Resources> <Grid x:Name="LayoutRoot" > <ListBox x:Name="caseListBox" ItemTemplate="{StaticResource caseTemplate}" Width="440" Foreground="White" SelectionChanged="caseInfo_SelectionChanged" /> <!--<helpers:PopupSplash x:Name="pop" />--> </Grid>复制代码
用户控件.cs页面代码
public int Kind { get; set; } public CaseListControl() { InitializeComponent(); } private void UserControl_Loaded(object sender, RoutedEventArgs e) { WebClient client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); string url = "http://localhost/caseList.aspx?kind=" + Kind; client.DownloadStringAsync(new Uri(url)); } public void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { var xml = XElement.Parse(e.Result); var videosTemp = ( from p in xml.Descendants("CaseList") select new caseList() { title = p.Element("title").Value, ImageUri = p.Element("ImageUri").Value, LogoUri = p.Element("LogoUri").Value, Type = p.Element("Type").Value, id = p.Element("id").Value }).ToList(); caseListBox.Items.Clear(); videosTemp.ForEach(p => caseListBox.Items.Add(p)); //pop.Visibility = Visibility.Collapsed; } } private void caseInfo_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (caseListBox.SelectedIndex != -1) { caseList curCity = (caseList)caseListBox.SelectedItem; (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/CaseInfo.xaml?id=" + curCity.id, UriKind.Relative)); } }复制代码
2.Pivot(案例分类展示页面)
<Grid x:Name="LayoutRoot" Background="Transparent"> <!--枢轴控件--> <controls:Pivot Title="案例共享" Name="CasePivot" LoadingPivotItem="Pivot_LoadingPivotItem" SelectionChanged="CasePivot_SelectionChanged"> <!--枢轴项一--> <controls:PivotItem Header="文化传播"> <Grid> </Grid> </controls:PivotItem> <!--枢轴项二--> <controls:PivotItem Header="医疗"> <Grid> </Grid> </controls:PivotItem> <!--枢轴项三--> <controls:PivotItem Header="教育"> <Grid> </Grid> </controls:PivotItem> <!--枢轴项四--> <controls:PivotItem Header="政府机构"> <Grid/> </controls:PivotItem> <!--枢轴项五--> <controls:PivotItem Header="建筑规划"> <Grid/> </controls:PivotItem> <!--枢轴项六--> <controls:PivotItem Header="广告"> <Grid/> </controls:PivotItem> <!--枢轴项七--> <controls:PivotItem Header="能源"> <Grid/> </controls:PivotItem> <!--枢轴项八--> <controls:PivotItem Header="IT"> <Grid/> </controls:PivotItem> </controls:Pivot> </Grid>复制代码
Pivot(案例分类展示页面).cs页面代码
private void Pivot_LoadingPivotItem(object sender, PivotItemEventArgs e) { int Kind = Convert.ToInt32(NavigationContext.QueryString["Kind"]); switch (Kind) { case 13: (CasePivot.Items[0] as PivotItem).Content = new CaseListControl() { Kind = 13 }; break; case 12: (CasePivot.Items[1] as PivotItem).Content = new CaseListControl() { Kind = 12 }; break; case 11: (CasePivot.Items[2] as PivotItem).Content = new CaseListControl() { Kind = 11 }; break; case 10: (CasePivot.Items[3] as PivotItem).Content = new CaseListControl() { Kind = 10 }; break; case 9: (CasePivot.Items[4] as PivotItem).Content = new CaseListControl() { Kind = 9 }; break; case 8: (CasePivot.Items[5] as PivotItem).Content = new CaseListControl() { Kind = 8 }; break; case 7: (CasePivot.Items[6] as PivotItem).Content = new CaseListControl() { Kind = 7 }; break; case 4: (CasePivot.Items[7] as PivotItem).Content = new CaseListControl() { Kind = 4 }; break; default: break; } } private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { int Kind = Convert.ToInt32(NavigationContext.QueryString["Kind"]); switch (Kind) { case 13: CasePivot.SelectedIndex = 0; break; case 12: CasePivot.SelectedIndex = 1; break; case 11: CasePivot.SelectedIndex = 2; break; case 10: CasePivot.SelectedIndex = 3; break; case 9: CasePivot.SelectedIndex = 4; break; case 8: CasePivot.SelectedIndex = 5; break; case 7: CasePivot.SelectedIndex = 6; break; case 4: CasePivot.SelectedIndex = 7; break; default: break; } } private void CasePivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { int item = CasePivot.SelectedIndex; switch (item) { case 0: (CasePivot.Items[0] as PivotItem).Content = new CaseListControl() { Kind = 13 }; break; case 1: (CasePivot.Items[1] as PivotItem).Content = new CaseListControl() { Kind = 12 }; break; case 2: (CasePivot.Items[2] as PivotItem).Content = new CaseListControl() { Kind = 11 }; break; case 3: (CasePivot.Items[3] as PivotItem).Content = new CaseListControl() { Kind = 10 }; break; case 4: (CasePivot.Items[4] as PivotItem).Content = new CaseListControl() { Kind = 9 }; break; case 5: (CasePivot.Items[5] as PivotItem).Content = new CaseListControl() { Kind = 8 }; break; case 6: (CasePivot.Items[6] as PivotItem).Content = new CaseListControl() { Kind = 7 }; break; case 7: (CasePivot.Items[7] as PivotItem).Content = new CaseListControl() { Kind = 4 }; break; default: break; } }复制代码
最终效果图:
相关文章推荐
- windows phone 7 用户控件页面跳转
- DNN下布局用户控件以及设置页面跳转
- 利用用户控件实现无刷新的页面跳转
- 关于用户控件的页面跳转问题 from http://blog.csdn.net/moxiaomomo/article/details/7439027
- 关于用户控件的页面跳转问题
- 页面装载用户控件时的事件顺序 (转)
- 解决用户控件调用主页面控件的问题.
- 同一页面,不同用户控件间的控制
- (论坛答疑点滴)如何在用户控件内得到包含这个用户控件的页面中的控件的值
- 使用MVC框架中要注意的问题:如何在页面和用户控件之间传递数据
- FreeCMS商业版 用户session失效后跳转页面地址修改
- MVC判断用户有没有登陆跳转登录页面AuthorizeAttribute
- 用户控件与主页面之间交换变量
- 怎样越过验证控件跳转到其它页面
- (转)向页面动态载入用户控件和自定义控件的方法(谨记)
- c#的aspx页面中引用了用户控件,如何相互调用后台方法
- 用户控件使用事件与调用页面交互
- 用户控件调用父页面方法
- Android listView中点击item或Item中控件跳转对应的详情页面的实现(商品详情查看)
- 用户控件如何控制ASPX页面的控件