4

ローカルのSqlCeデータベースを使用するMangoWP7.5アプリがあります。現在の日と月に基づいてローカルDBから取得した情報を表示するLiveTileアップデートを追加したいと思います。

私が見つけたすべてのサンプルは、サーバーからリモートイメージをダウンロードすることで背景を更新しますが、ローカルデータベースクエリを作成し、タイルに文字列を表示するだけで済みます。

できますか?どのように?

4

1 に答える 1

7

はい、できます。必ず

  1. テキスト情報を含む画像を生成する
  2. このイメージを分離ストレージに保存し、
  3. isostoreURI経由でアクセスします。

これを行う方法を示すコードは次のとおりです(アプリケーションタイルを更新します)。

// set properties of the Application Tile
private void button1_Click(object sender, RoutedEventArgs e)
{
    // Application Tile is always the first Tile, even if it is not pinned to Start
    ShellTile TileToFind = ShellTile.ActiveTiles.First();

    // Application Tile should always be found
    if (TileToFind != null)
    {
        // create bitmap to write text to
        WriteableBitmap wbmp = new WriteableBitmap(173, 173);
        TextBlock text = new TextBlock() { FontSize = (double)Resources["PhoneFontSizeExtraLarge"], Foreground = new SolidColorBrush(Colors.White) };
        // your text from database goes here:
        text.Text = "Hello\nWorld";
        wbmp.Render(text, new TranslateTransform() { Y = 20 });
        wbmp.Invalidate();

        // save image to isolated storage
        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            // use of "/Shared/ShellContent/" folder is mandatory!
            using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/MyImage.jpg", System.IO.FileMode.Create, isf))
            {
                wbmp.SaveJpeg(imageStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
            }
        }

        StandardTileData NewTileData = new StandardTileData
        {
            Title = "Title",
            // reference saved image via isostore URI
            BackgroundImage = new Uri("isostore:/Shared/ShellContent/MyImage.jpg", UriKind.Absolute),
        };

        // update the Application Tile
        TileToFind.Update(NewTileData);
    }
}
于 2011-11-06T22:27:25.423 に答える