0

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

Houy Narun
  • 1,557
  • 5
  • 37
  • 86

1 Answers1

0

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()

Filip
  • 1,824
  • 4
  • 18
  • 37
  • Sorry, I'm not clear what you said. Did you mean this: `Uri uri = new Uri("/All Files/Product Files/Dry/Product Detail.xaml?item_image=" + imageBase + "&id="+id, UriKind.Relative);`? then how to check if the particular id is matched when user click secondary tile from the start menu in order to display image correctly? Would be very appriciate if you could provide example code about this, thanks – Houy Narun Sep 21 '14 at 12:50
  • No, sorry I wasnt clear enough. Your Uri for loading images should look like this new Uri("[path to image folder]/image" + Id + ".png", Urikind.Relative); Assuming you have image files named the way I have described. – Filip Sep 21 '14 at 17:09
  • Very much thank you for your support, now all are well done. first I sent the image id from the prevouse page, and at new page at OnNavigationTo(), I use `Uri uri = new Uri("/All Files/Product Files/Dry/Product Detail.xaml?item_image=" + imageBase + "&id="+id`. Then I query all products item in my xml file where all information are stored. – Houy Narun Sep 21 '14 at 18:13
  • Next, I used foreach loop like this and find the image for the specific id but since the image path in xml file start with .../, I have to use subString for the correct path for xaml file `foreach(ProductsDry list in productListData) { if(list.ItemDryId==idd) { imageBase = list.ItemDryImage; imageBase = imageBase.Substring(9); } } ` – Houy Narun Sep 21 '14 at 18:15
  • 1
    Finally, I follow the rest code in OnNavigationTo, and can display image and relevant information correctly. Thanks again Parad1s3 for your help :) – Houy Narun Sep 21 '14 at 18:17