0

I have created a web browser for wp7. Below is the codes i have used in my app. But what happens is the image is blank(white image)See Image Below. Can anybody help me with this? Thanks for your help.

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 Answers2

1

what you need to do is, render the html insider a writeablebitmap and save the resultant as 173x173 file.

I am not sure if you can render webbrowser control like IE can.

you are out of luck.. read this https://stackoverflow.com/a/6479233/1306871

webbrowser doesn't render in a writeablebitmap due to some bug

Community
  • 1
  • 1
Hermit Dave
  • 3,036
  • 1
  • 13
  • 13
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);}

write code to create tile hope helpful...

Archana
  • 376
  • 2
  • 12