How to Create CycleTile Dynamically in Windows Phone 8
I would like to use the new Cycle Tile feature available in Windows Phone
8, although I am having trouble creating this dynamically. My issue arises
when attempting to set the images for the Cycle Tile, I do not seem to be
getting the correct paths for the images. What I have so far is as follows
MainPage.xaml.cs
private void CreateApplicationTile()
{
//App.PictureList.Pictures grabs all of my application images from
IsolatedStorage
int count = App.PictureList.Pictures.Count();
int count1 = count - 9;
var cycleImages = new List<Uri>();
if (count > 0)
{
//I only want to add the 9 most recent images if available
for (int i = count; i > count1; i--)
{
int index = i - 1;
if (index > -1)
{
//Set file to type CapturedPicture, which contains the
jpg, name, date, etc.
var file = App.PictureList.Pictures[index] as
CapturedPicture;
//TilePictureRepository class saves the file (picture)
to "Shared/ShellContent/"
//TilePictureRepository.IsolatedStoragePath =
"Shared/ShellContent/"
TilePictureRepository.Instance.SaveToLocalStorage(file,
TilePictureRepository.IsolatedStoragePath);
}
}
}
// Select the application tile
ShellTile myTile = ShellTile.ActiveTiles.First();
if (myTile != null)
{
Uri[] u = new Uri[9];
using (IsolatedStorageFile isf =
IsolatedStorageFile.GetUserStoreForApplication())
{
IEnumerable<string> files =
isf.GetFileNames(TilePictureRepository.IsolatedStoragePath
+ "*").Reverse();
int x = 0;
foreach (string file in files)
{
if (x < 9)
{
u[x] = new Uri("isostore:/Shared/ShellContent/" +
file, UriKind.Absolute);
cycleImages.Add(u[x]);
x++;
}
}
}
CycleTileData newTileData = new CycleTileData
{
Title = "Tile Test",
SmallBackgroundImage = new
Uri("/Assets/Tiles/Tile_Small_159x159.png",
UriKind.Relative),
CycleImages = cycleImages,
};
myTile.Update(newTileData);
}
}
From what I understand, tile images for the Cycle Tile should be saved in
the ShellTile directory within IsolatedStorage. To do this, I am using the
following class which I quickly modified (I really only am using the
SaveToLocalStorage method)
TilePictureRepository.cs
#region Constants
public const string IsolatedStoragePath = "Shared/ShellContent/";
No comments:
Post a Comment