Search code examples
c#windows-phone-7uritilereddit

Trying to set a tile's background to images from the internet


When I execute this code the tile will be empty, Can anyone explain to me why and how to fix it?

private void CreateCycleTileWide()
    {
        if (!Mangopollo.Utils.CanUseLiveTiles)
        {
            MessageBox.Show("This feature needs Windows Phone 7.8");
            return;
        }

        try
        {

This code gets a json feed from reddit, submission.data.thumbnail looks like "http://someaddress.com/something.png".

            Submission orig;
            for (int cur = 0; cur < App.ViewModel.PicsSubmissionList.Count; cur++)
            {
                orig = App.ViewModel.PicsSubmissionList[cur];
                Submission submission = orig;

                Dispatcher.BeginInvoke(() =>
                {

                    if (!string.IsNullOrEmpty(submission.data.thumbnail))
                    {
                        try
                        {
                            list.Add(new Uri(submission.data.thumbnail));
                        }
                        catch { MessageBox.Show("Can't generate list"); }
                    }
                });
            }

This code creates the tile from the previous list of URIs.

            try
            {
                var mytile = new CycleTileData
                {
                    Title = "Reddit /r/Pics",
                    Count = 0,
                    SmallBackgroundImage = new Uri("/images/RedditLogo.png", UriKind.Relative),
                    CycleImages = list
                };
                ShellTileExt.Create(new Uri("/MainPage.xaml?msg=fromwidetile", UriKind.Relative), mytile, true);
            }
            catch { MessageBox.Show("cantcreatetile"); }
        }
        catch
        {
            MessageBox.Show("remove tile before creating it again");
        }
    }

Thanks in advance, Max.


Solution

  • All types of tiles support only local images. Remote images (not on the device) are not supported. You should save your remote images to isolated storage first.