如何在shell tile上为wp7创建一个网页

时间:2012-07-26 15:25:50

标签: c# windows-phone-7

我为wp7创建了一个Web浏览器。以下是我在我的应用中使用的代码。但是会发生什么是图像是空白的(白色图像)请参见下面的图像。任何人都可以帮我吗?谢谢你的帮助。

private void PinToStart_Click(object sender, EventArgs e)
    {
        string _url = UrlTextBox.Text;

        ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("url=" + _url));

        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            var bmp = new WriteableBitmap(173, 173);
            var tt = new TranslateTransform();
            tt.X = 0;
            tt.Y = 0;
            bmp.Render(browsers[this.currentIndex], tt);
            bmp.Invalidate();
            var filename = "/Shared/ShellContent/01d.jpg";
            using (var st = new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, store))
            {
                bmp.SaveJpeg(st, 173, 173, 0, 100);
            }
        }

        // Create the Tile if we didn't find that it already exists.
        if (TileToFind == null)
        {
            StandardTileData NewTileData = new StandardTileData
            {
                BackgroundImage = new System.Uri("isostore:/Shared/ShellContent/01d.jpg", System.UriKind.Absolute),
                Title = string.Format(_url.Substring(7)),
                BackTitle = "Browser",
                BackContent = (string)_url.Substring(7),
                BackBackgroundImage = new Uri("", UriKind.Relative)
            };

            // Create the Tile and pin it to Start. This will cause a navigation to Start and a deactivation of our application.
            ShellTile.Create(new Uri("/Web.xaml?passedUrl=" + _url, UriKind.Relative), NewTileData);
        }
        else
        {
            MessageBox.Show("A live tile already created for this service. Please check it out!!!");
        }
    }

enter image description here

2 个答案:

答案 0 :(得分:1)

你需要做的是,将html内幕渲染成一个writeablebitmap并将结果保存为173x173文件。

我不确定你是否可以像IE一样呈现webbrowser控件。

你运气不好..请阅读https://stackoverflow.com/a/6479233/1306871

由于某些错误,

webbrowser无法在writeablebitmap中呈现

答案 1 :(得分:1)

Canvas canvas = new Canvas();
canvas .Width = 173;
canvas.Height = 173;
WriteableBitmap wpm= new WriteableBitmap(173, 173);
using (MemoryStream mem = new MemoryStream()){Image image = new Image();
image.Source = browsers[this.currentIndex];
can.Children.Add(image);                   
TranslateTransform translateTransform = new TranslateTransform();
translateTransform.X = 0;
translateTransform.Y = 0;
wpm.Render(canvas, translate Transform);
}    
wpm.Invalidate();                
wpm.SaveJpeg(mem, 768, 200, 0, 100);
var filename = "/Shared/ShellContent/01d.jpg";
using (var st = new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, store)){bmp.SaveJpeg(st, 173, 173, 0, 100);}

编写代码来创建磁贴 希望有帮助...