我想用直接网站创建一个带有背景图片的标准,
我在wp8做得很好, 但是相同的代码在wp7中不起作用
这是下面的代码:
void setTile(string title, string IconPath1x1, string IconPath2x2,
string IconPath4x2, string IconPath2x2Back, string IconPath4x2Back,
string wideContent, string targetUri)
{
StandardTileData Standarddata = new StandardTileData()
{
//IconPath2x2 = "http://i.imgur.com/something.png"
Title = title + "_",
BackgroundImage = new Uri(IconPath2x2, UriKind.RelativeOrAbsolute),
BackContent = "",
BackTitle = title + "_",
BackBackgroundImage = new Uri(IconPath1x1, UriKind.Absolute)
};
ShellTile tiletopin = ShellTile.ActiveTiles.FirstOrDefault(
x => x.NavigationUri.ToString().Contains(targetUri));
if (tiletopin == null)
{
ShellTile.Create(
new Uri(targetUri, UriKind.RelativeOrAbsolute), Standarddata);
}
}
我试过这个链接,但它不起作用
http://blog.safaribooksonline.com/2012/03/20/windows-phone-7-bringing-your-application-tile-to-life/
我错过了什么或者它在wp7中不起作用吗?
答案 0 :(得分:2)
不幸的是,您需要下载图片并将其保存在本地。然后,您可以参考隔离存储中的图像
string fileName = @"Shared\ShellContent\backgroundTileImage.jpg";
if(TrySaveImage(fileName, "http://foo.com/bar.png"))
{
Uri uri = new Uri("isostore:/" + fileName, UriKind.Absolute);
// Create the tile if we didn't find it already exists.
var tileData = new StandardTileData
{
Title = "My Tile",
BackgroundImage = uri,
};
}
...
private bool TrySaveImage(string fileName, string url)
{
using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
var backImage = new Image();
backImage.Height = backImage.Width = 173;
backImage.Stretch = Stretch.None;
backImage.Source = new BitmapImage(new Uri(url));
backImage.Measure(new Size(173, 173));
backImage.Arrange(new Rect(0, 0, 173, 173));
var image = new WriteableBitmap(backImage, null);
string directory = Path.GetDirectoryName(fileName);
if (!store.DirectoryExists(directory))
{
store.CreateDirectory(directory);
}
using (var stream = store.OpenFile(fileName, FileMode.OpenOrCreate))
{
image.SaveJpeg(stream, 173, 173, 0, 100);
}
}
catch
{
return false;
}
}
return true;
}