Search code examples
c#xamlwindows-8.1secondary-live-tile

Windows 8 Secondary Tile using Templates


I have a windows store app that currently allows my users to pin and unpin tiles to the start menu. I am able to set a background and logo and text but the problem is I want the tile to instead of a static logo with text I want it to be sort of a live tile.

So it would go from one side with just an image and then flip and the other side would be my app information. I know you are able to do this for regular live tiles and using xml, but I am using c# and would like for this to work in my secondary tile.

Any help on how to go about that would be great.

Here is some code I used to create the secondary tile:

private async void PinButton_OnClick (object sender, RoutedEventArgs e) { var item = createdItem.SelectedItem;

if (item != null)
{
    var logo = new Uri(item.image);
    if (item != null)
    {
        var smallLogo = new Uri(item.image);
        var wideLogo = new Uri(item.image);
    }

    string tileActivationArguments = logoSecondaryTileId + "WasPinnedAt=" +
                                     DateTime.Now.ToLocalTime();
    logoSecondaryTileId = item.ID+ counter.ToString();
    counter++;

    //Create the tile
    SecondaryTile tile = new SecondaryTile(logoSecondaryTileId, item.Code, item.FirstName + " " + item.LastName,
        tileActivationArguments, TileOptions.ShowNameOnLogo | TileOptions.ShowNameOnWideLogo, logo);

    if (item.SelectedItem is Details)
    {

        tile.ForegroundText = ForegroundText.Light;
        tile.BackgroundColor = Colors.Black;


        bool isPinned =
            await
                tile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender),
                    Placement.Default);


        if (isPinned)
        {
            Messages.InvokeToast(Toast.Created);
            UnpinButton.Visibility = Visibility.Visible;
            pinButton.Visibility = Visibility.Collapsed;
        }
        else
        {
            Messages.InvokeToast(Toast.Error);
        }

        if (SecondaryTile.Exists(logoSecondaryTileId))
        {
            var dialog = new MessageDialog("Already exists!")
            {
                Title = "Unable to Pin Tile!"
            };
            dialog.Commands.Add(new UICommand("Okay", new UICommandInvokedHandler(CommandHandler)));
            dialog.CancelCommandIndex = 1;
            await dialog.ShowAsync();
        }

    }
}
}

Solution

  • You just need to define the tile using a template that has a front and back. See here for how to define secondary tiles with templates: Is it possible to use tile templates with secondary tiles in a Windows Store App?. See here for the list of possible templates and which have backs: http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx