简体   繁体   中英

Unable to set multiple secondary tiles in windows phone 8

I want to be able to pin page from where the user has navigated to, I want to make its content shows dynamically depending on which item the user has selected to pin. The first secondary tile, I could do it, but the problem is that when there are more than one secondary tile at the start menu, all the secondary tiles are link to the page but the content of the page is all the same as the last secondary tile.

Here is what I do:

From where the page is navigated to, I receive the information and set it display on the page like this:

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


            if (!IsolatedStorageSettings.ApplicationSettings.Contains("isolated_image"))
            {
                IsolatedStorageSettings.ApplicationSettings.Add("isolated_image", NavigationContext.QueryString["pro_image"] as string);
            }
![enter image description here][1]
            imageBase = (IsolatedStorageSettings.ApplicationSettings["isolated_image"] as string);

            StreamResourceInfo sri = null;


            Uri uri = new Uri(imageBase, UriKind.Relative);
            uriString = uri.ToString();
            sri = Application.GetResourceStream(uri);
            BitmapImage bitmap = new BitmapImage();
            bitmap.SetSource(sri.Stream);

            base64 = ((App)Application.Current).ImageToBase64(bitmap);

            item_image.Source = ((App)Application.Current).ImageFromBase64(base64);

            if (!(IsolatedStorageSettings.ApplicationSettings.Contains("item_name")))
            {
                IsolatedStorageSettings.ApplicationSettings.Add("item_name", PhoneApplicationService.Current.State["pro_name"]);

            }

            ShellTile secondaryTile = this.FindTile(SecondaryTileUriSource);

            if (secondaryTile != null)
            {

                item_image.Source = ((App)Application.Current).ImageFromBase64(base64);
            }

            txtb_product_name.Text = PhoneApplicationService.Current.State["pro_name"] as string;            

        }

From information I got, when the user press on pin app bar, I create the secondary tile with the unique uri based on "?image_item="+imageBase

  void btnPin_Click(object sender, EventArgs e)
        {       
            ShellTile tile = this.FindTile(SecondaryTileUriSource);
            if(tile==null)
            {

                StandardTileData tileData = this.GetSecondaryTileData();

                 Uri uri = new Uri("/All Files/Product Files/Dry/Product Detail.xaml?item_image=" + imageBase, UriKind.Relative);

                 MessageBox.Show("the link uri is "+ uri.ToString());

                ShellTile.Create(uri, tileData);


            }
        }

At the end, when I have have multiple secondary tiles at the start menu, the first, and the second secondary tiles will displays the same content on the page like this last secondary tile that I pinned.

I'm sure that the link uri is already unique; otherwise, I could not create multiple secondary tiles. Can anyone help me what's wrong? Thanks

First, I'd change your pinning logic and instead of creating string from your image data use some sort of ID to identify image... You current approach is unnecessary complicated.

It could be as simple as to have: image1,image2, image3 and so on. Then get id from query string and construct image uri like: new Uri("../image" + id)

If you have successfully created multiple secondary tiles, then each must be unique and your problem probably lies in parsing query strings in your OnNavigatedTo()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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