我可以使用本地数据更新 Mango 中的动态磁贴吗? [英] Can I update a live tile in Mango using local data?

查看:21
本文介绍了我可以使用本地数据更新 Mango 中的动态磁贴吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用本地 SqlCe 数据库的 Mango WP7.5 应用程序.我想添加一个 LiveTile 更新,显示根据当前日期和月份从本地数据库获取的信息.

I have a Mango WP7.5 app that uses a local SqlCe database. I would like to add a LiveTile update that shows info taken from the local DB based on current day and month.

我发现的所有示例都通过从服务器下载远程图像来更新背景,但我只需要进行本地数据库查询并在我的磁贴中显示一个字符串.

All the samples that I've found update the background by downloading remote images from servers but I would simply need to make a local database query and show a string in my tile.

我可以吗?怎么样?

推荐答案

是的,你可以.你必须

  1. 生成包含您的文本信息的图像
  2. 将此图像保存到独立存储和
  3. 通过 isostore URI 访问它.
  1. generate an image containing your textual information
  2. save this image to isolated storage and
  3. access it via isostore URI.

以下代码显示了如何执行此操作(它更新应用程序磁贴):

Here is code showing how to do this (it updates the Application Tile):

// 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
World";
        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);
    }
}

这篇关于我可以使用本地数据更新 Mango 中的动态磁贴吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆