Windows Phone 实用开发技巧(17):自定义应用程序的Tile
下面讲讲稍微高级一点的知识
1. 在代码中合成图片
我在项目中会用到如下三张图片:

第一张BackBg.png是用于Secondary Tile的背景图片,用于和第三张图片合成,生成一张新的Secondary Tile的背景图片,中间一张图片即Tile的背景图片,最终的效果图如下图:
合成图片的思想是利用WriteableBitmap可以将UIElement保存为图片,下面是详细代码:
{
Grid grid = new Grid
{
Background = new ImageBrush
{
ImageSource = new BitmapImage
{
UriSource = new Uri("/mangTile;component/Images/BackBg.png", UriKind.Relative),
CreateOptions = BitmapCreateOptions.IgnoreImageCache
}
},
Width = 173,
Height = 173
};
Image profileImg = new Image
{
Height=48,
Width=48,
Source = new BitmapImage
{
UriSource = new Uri("/mangTile;component/Images/u97911.jpg", UriKind.Relative),
CreateOptions = BitmapCreateOptions.IgnoreImageCache
},
};
grid.Children.Add(profileImg);
grid.Arrange(new Rect(0d, 0d, 173, 173));
WriteableBitmap wbmp = new WriteableBitmap(grid, null);
string tiledirectory = "Shared/ShellContent/tiles";//note :父目录必须是 Shared/ShellContent
string fullPath = tiledirectory + @"/" + "LiveTile.jpg";
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!store.DirectoryExists(tiledirectory))
{
store.CreateDirectory(tiledirectory);
}
using (var stream = store.OpenFile(fullPath, System.IO.FileMode.OpenOrCreate))
{
wbmp.SaveJpeg(stream, 173, 173, 0, 100);
}
}
return "isostore:/" + fullPath;}
{
BackgroundImage=new Uri("/Background.png"),
Title = "",
BackTitle = "Secondary",
BackBackgroundImage = new Uri(CreateBackground())
};
ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative),std);
2. ShellTile 的ActiveTiles属性
MSDN的解释为Contains the collection of an applications tiles pinned to Start. 就是包含应用程序已经Pin to start的集合,要注意的是:
第一、指的是当前的应用程序,而不是所有的应用程序
第二、不管你的应用程序有没有Pin To Start, ActiveTiles中始终包含一个默认的Tile(Uri为”/“),而且始终为第一个
第三、如果你讲Uri为“/MainPage.xaml” Pin到桌面了,则ActiveTiles包含两个Tile(Uri分别为“/”与/MainPage.xaml)
如果您喜欢我的文章,您可以通过支付宝对我进行捐助,您的支持是我最大的动力https://me.alipay.com/alexis
作者:Alexis
出处:http://www.cnblogs.com/alexis/
关于作者:专注于Windows Phone 7、Silverlight、Web前端(jQuery)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过shuifengxuATgmail.com 联系我,非常感谢。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库