0
votes

I'm trying to render a UserControl as an image, and then assign it to a secondary tile and pin it. The resulting URI is

isostore:/Shared/ShellContent/CustomTile.jpg

However, I get the following error: ExceptionObject = {System.ArgumentException: Value does not fall within the expected range. at Windows.UI.StartScreen.SecondaryTileVisualElements.put_Square150x150Logo(Uri value) at NestWP.ActionTiles.d__1.MoveNext()

I have this piece of code

        var customTile = new ActionTileControl();
        customTile.Measure(new Size(150, 150));
        customTile.Arrange(new Rect(0, 0, 150, 150));

        var bmp = new WriteableBitmap(150, 150);
        bmp.Render(customTile, null);
        bmp.Invalidate();

        const string filename = "/Shared/ShellContent/CustomTile.jpg";

        using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (!isf.DirectoryExists("/CustomLiveTiles"))
            {
                isf.CreateDirectory("/CustomLiveTiles");
            }
            using (var stream = isf.OpenFile(filename, System.IO.FileMode.OpenOrCreate))
            {
                bmp.SaveJpeg(stream, 336, 366, 0, 100);
                stream.Close();
            }
            bool ex = isf.FileExists(filename);

            ex = ex;
        }

        string urilink = "isostore:" + filename;

        SecondaryTile secondaryTile = new SecondaryTile()
        {
            TileId = "tileid",
            DisplayName = "title",
            Arguments = "args"
        };
        //Error on the line below
        secondaryTile.VisualElements.Square150x150Logo = new Uri(urilink, UriKind.Absolute); 
        secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = false;
        bool isPinned = await secondaryTile.RequestCreateAsync();

I checked FileExists and the bool returns true.

How can I get the image to be set as secondary tile?

1

1 Answers