How to create a SecondaryTile on Windows Phone 8.1?

345 Views Asked by At

I'm trying to create a Tile on the Windows Phone start screen. The following code used to work but now it doesn't. I didn't change anything.

    private async static void CreateTile()
    {
        try
        {
            SecondaryTile tileData = new SecondaryTile()
            {
                TileId = "MyTileID",
                DisplayName = "My App Name",
                TileOptions = TileOptions.ShowNameOnLogo,
            };

            tileData.VisualElements.Square150x150Logo = new Uri("ms-appx:///Resources/Images/Tiles/150150.png", UriKind.Absolute);
            tileData.VisualElements.ShowNameOnSquare150x150Logo = true;

            await tileData.RequestCreateAsync();
        }
        catch (Exception ex)
        {

        }
    }

Now it's failing with the error message:

The parameter is incorrect.

and the following Stack Trace:

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at My.Namespace.SplashPage.<CreateTile>d__f.MoveNext()

I even get the error when I comment everything out, for example:

SecondaryTile tileData = new SecondaryTile()
{
    //TileId = "MyTileID",
    //DisplayName = "My App Name",
    //TileOptions = TileOptions.ShowNameOnLogo,
};

//tileData.VisualElements.Square150x150Logo = new Uri("ms-appx:///Resources/Images/Tiles/150150.png", UriKind.Absolute);
//tileData.VisualElements.ShowNameOnSquare150x150Logo = true;

await tileData.RequestCreateAsync();

So I don't know what parameter is incorrect. What could be causing this? How can I fix it?

1

There are 1 best solutions below

0
On

Try something like this:

    if (SecondaryTile.Exists(tileID)) await tileData.UpdateAsync();
    else await tileData.RequestCreateAsync();