简体   繁体   English

WP7在页面之间传递多个数据

[英]WP7 passing multiple pieces of data between pages

In my app I am building my own media player. 在我的应用程序中,我正在构建自己的媒体播放器 When a user selects a song to play want to be able to pass the link to the sample media and the metadata associated with it (Artist, Track, Album Art, etc.) The part I'm stuck on is how to group all the data and pass it to the media player page. 当用户选择要播放的歌曲时,希望能够将链接传递给样本媒体以及与其关联的元数据(艺术家,曲目,专辑艺术等)。我所坚持的部分是如何将所有数据并将其传递到媒体播放器页面。 Here's what i have so far. 这是我到目前为止所拥有的。

Determine what item was selected and add data to query string. 确定选择了哪个项目并将数据添加到查询字符串。

UPDATED 更新

    public void musicSampleSelectedHandler(object sender, RoutedEventArgs e)
    {
        Track selected = (sender as Image).DataContext as Track;
        ListBoxItem pressedItem = this.listReleaseMain.ItemContainerGenerator.ContainerFromItem(selected) as ListBoxItem;
        if (pressedItem != null)
        {
            string _rT = selected.title;
            string _rN = selected.release.name;
            //string _rA = selected.artists; ????
            string _rI = selected.images.large.url;
            string _rS = selected.sampleUrl;

            this.NavigationService.Navigate(new Uri("/Pages/MediaPage.xaml?releaseName=" + _rN + "&releaseTrack=" + _rT + "&releaseImage=" + _rI
                + "&releaseSample=" + _rS, UriKind.Relative));
        }
    }

OnNavigatedTo method to pull data out of the query string OnNavigatedTo方法从查询字符串中提取数据

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        string releaseName = String.Empty;
        string releaseImg = String.Empty;
        string releaseUrl = String.Empty;

        if (NavigationContext.QueryString.TryGetValue("releaseUrl", out releaseUrl))
        {
            sampleMedia.Source = new Uri(releaseUrl, UriKind.Absolute);
        }
    }

I'm not sure if I can use the query sting to pass multiple pieces to the media player, or if I to do something different to pass the data to the other page. 我不确定我是否可以使用查询sting将多个片段传递给媒体播放器,或者我是否要做一些不同的事情来将数据传递到另一个页面。 All of my data comes from the web using a webclient. 我的所有数据都来自使用webclient的网络。 Thanks for the help. 谢谢您的帮助。

QueryString is just a Dictionary of the parameters passed in via the Uri. QueryString只是通过Uri传入的参数的字典。 The Uri uses the standard syntax of passing in parameters delimited by & . Uri使用传入由&分隔的参数的标准语法。 So in your example, if you had something like: 所以在你的例子中,如果你有类似的东西:

this.NavigationService.Navigate(new Uri("/Pages/MediaPage.xaml?releaseUrl=" + releaseUrl + "&releaseImg=" + releaseImg , UriKind.Relative)); 

then you can then parse this out using something like: 然后你可以使用类似的东西解析它:

if (NavigationContext.QueryString.TryGetValue("releaseUrl", out releaseUrl))   
{   
    sampleMedia.Source = new Uri(releaseUrl, UriKind.Absolute);   
} 

if (NavigationContext.QueryString.TryGetValue("releaseImg", out releaseImg))   
{   
    // do something with releaseImg
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM