尝试将图块的背景设置为来自互联网的图像

时间:2013-01-29 15:41:20

标签: c# windows-phone-7 uri tile reddit

当我执行此代码时,磁贴将为空,任何人都可以向我解释为什么以及如何解决它?

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

        try
        {

此代码从reddit获取json提要,submission.data.thumbnail看起来像“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"); }
                    }
                });
            }

此代码根据上一个URI列表创建磁贴。

            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");
        }
    }

提前致谢,Max。

1 个答案:

答案 0 :(得分:1)

所有类型的图块仅支持本地图像。不支持远程图像(不在设备上)。你应该先save your remote images to isolated storage