当前位置:编程学习 > wap >>

windows phone 7 用户控件页面跳转

做项目时遇到一个产品分类展示的页面,于是用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));
              
            }
        }

补充:移动开发 , Windows Phone ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,