带有PNG和自定义颜色的WP7平铺

时间:2012-05-02 10:06:36

标签: c# windows-phone-7 dynamic png

是否有可能在WP7中添加动态Tile,我在中心获取带有我的徽标的PNG文件并为其添加背景颜色?

它应该是这样的:

enter image description here

目前我像这样创建我的Tiles:

private void addShortcut_Click(object sender, EventArgs e)
    {
        string Url = GlobalVariables.Uri;
        StandardTileData NewTileData = new StandardTileData
        {
            BackgroundImage = new Uri("img/red.jpg", UriKind.Relative),
            Title = "Energy "+GlobalVariables.Name,
            Count = 0,
            BackTitle = "Radion Energy",
            BackContent = "Hitmusic Only!",
            BackBackgroundImage = new Uri("img/test.jpg", UriKind.Relative)
        };
        try
        {
            // Create the Tile and pin it to Start. This will cause a navigation to Start and a deactivation of our application.
            ShellTile.Create(new Uri("/MainPage.xaml?stationName=" + stationName + "&tile=true&name=" + GlobalVariables.Name + "&url=" + Url, UriKind.Relative), NewTileData);
        }
        catch
        {
            MessageBox.Show("Channel-Tile exists already.");
        }
    }

所以目前背景总是与Phonestyle本身颜色相同。 (我真的不明白为什么因为red.jpg实际上是一个红色方块。:)而且目前我没有徽标,所以它只是空白。

谢谢:)

4 个答案:

答案 0 :(得分:1)

您确定自己的图片是否设为“内容”?

答案 1 :(得分:1)

我使用了Ree7 Tile Toolkit,它允许您使用自定义背景颜色设置磁贴,源代码包含一个示例项目,解释并演示如何使用该工具包: -

http://wp7tiletoolkit.codeplex.com/

答案 2 :(得分:1)

private const string FLICKR_LIVE_TILE = "/Shared/ShellContent/flickr_live_tile.jpg";
private const string FLTile = "/Shared/ShellContent/FLTile.jpg";

使用您想要的任何来源准备WriteableBitmap

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
                if (myIsolatedStorage.FileExists(FLTile))
                {
                    myIsolatedStorage.DeleteFile(FLTile);
                }
                using (IsolatedStorageFileStream iso = new IsolatedStorageFileStream(FLTile, FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication()))
                {
                    WriteableBitmap1 .SaveJpeg(iso, 768, 200, 0, 100);
                    iso.Close();
                }
                if (myIsolatedStorage.FileExists(FLICKR_LIVE_TILE))
                {
                    myIsolatedStorage.DeleteFile(FLICKR_LIVE_TILE);
                }
                using (
             IsolatedStorageFileStream isoFileStream = new IsolatedStorageFileStream(FLICKR_LIVE_TILE, FileMode.OpenOrCreate,
             IsolatedStorageFile.GetUserStoreForApplication()))
                {
                    WriteableBitmap2 .SaveJpeg(isoFileStream, 336, 200, 0, 100);
                    isoFileStream.Close();
                }




                var shellTileData = new FlipTileData
                {
                    BackgroundImage = new Uri("isostore:" + FLICKR_LIVE_TILE, UriKind.RelativeOrAbsolute),
                    //BackContent = "Connectivity Slab",
                    SmallBackgroundImage = new Uri("isostore:" + FLICKR_LIVE_TILE, UriKind.RelativeOrAbsolute),
                    WideBackgroundImage = new Uri("isostore:" + FLTile, UriKind.RelativeOrAbsolute),
                    WideBackBackgroundImage = new Uri("isostore:" + FLTile, UriKind.RelativeOrAbsolute),
                    BackBackgroundImage = new Uri("isostore:" + FLICKR_LIVE_TILE, UriKind.RelativeOrAbsolute),
                };
                var tile = ShellTile.ActiveTiles.First();
                tile.Update(shellTileData);

它将有助于创建宽和短平铺图像

答案 3 :(得分:0)

如果它只显示一个Square,则表示您未正确设置图片的URI: - )

编辑:图片应设置在"内容" (已经提到过)