アプリケーションのタイル画像を更新する機能を追加する

#wp7dev_jp

これで更新できるかな。 タイル画像にこだわりたいユーザーのために、アプリにこういった機能があったらうれしい?

using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;

private void button1_Click(object sender, RoutedEventArgs e)
{
    if (MessageBox.Show("タイル画像を選択しますか?", "タイル更新", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
    {
        PhotoChooserTask photo = new PhotoChooserTask();
        photo.Completed += new EventHandler<PhotoResult>(photo_Completed);
        photo.Show();
    }
    else
    {
        if (MessageBox.Show("タイル画像をもとに戻しますか?", "タイル復帰", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            UpdateTile("Background.png");
    }
}

void photo_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {

        String filename = "/Shared/ShellContent/TileImage.jpg";

        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {

            //分離ストレージに画像を作成
            IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(filename);
            BitmapImage bmpImage = new BitmapImage();
            bmpImage.SetSource(e.ChosenPhoto);
            WriteableBitmap bmp = new WriteableBitmap(bmpImage);
            bmp.SaveJpeg(fileStream, 173, 173, 0, 90);

            String TileFile = "isostore:" + filename;
            UpdateTile(TileFile);
        }
    }
}

private static void UpdateTile(String filename)
{
    //タイル作成

    StandardTileData NewTileData = new StandardTileData
    {
        BackgroundImage = new Uri(filename, UriKind.RelativeOrAbsolute),
    };

    //タイルの更新
    ShellTile TileToFind = ShellTile.ActiveTiles.First();
    if (TileToFind != null)
    {
        TileToFind.Update(NewTileData);
        MessageBox.Show("更新しました。画像が変更されない場合はいったんタイルを削除してから、再度タイルを作成してください。");
    }
}