转新浪徐水峰博文-自定义WP7应用程序Title
来源:互联网 发布:软件系统流程图怎么画 编辑:程序博客网 时间:2024/06/11 07:29
在Windows Phone 7 (Nodo)之前的版本中,我们在应用程序列表中长按某个应用程序的时候,会弹出“Pin To Start”的选择,选中后系统会将该应用程序的快捷方式Pin到启动界面中,类似于Windows 上的桌面快捷方式。那时候呈现在启动界面的图片是应用程序中的Background.png,如果你没有改变该变片的话,Pin到Start中的图片大致如下:
在Mango中,我们可以做的更多(在Nodo中我们仅能改变背景图片和应用程序的显示名字),在Mango中,我们可以:
1. 动态更新Pin 到桌面的背景图片
2. 创建一个Secondary的Tile,让我们的Tile 变得更加Live
3. 可以使用Back Agent动态更新Count
马宁大大给出了一篇很好的入门文章《马宁的Windows Phone 7.1初体验(三)——Tile》
下面讲讲稍微高级一点的知识
1. 在代码中合成图片
我在项目中会用到如下三张图片:
第一张BackBg.png是用于Secondary Tile的背景图片,用于和第三张图片合成,生成一张新的Secondary Tile的背景图片,中间一张图片即Tile的背景图片,最终的效果图如下图:
合成图片的思想是利用WriteableBitmap可以将UIElement保存为图片,下面是详细代码:
public staticstring CreateBackground()
{
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;}
{
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;}
StandardTileData std =new StandardTileData
{
BackgroundImage=new Uri("/Background.png"),
Title ="",
BackTitle ="Secondary",
BackBackgroundImage =new Uri(CreateBackground())
};
ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative),std);
{
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)
源代码下载:
- 转新浪徐水峰博文-自定义WP7应用程序Title
- WP7 pin to start 自定义应用程序的Tile
- 自定义Title
- 自定义Title
- 自定义title
- 自定义title
- 自定义title
- WP7-Expression Blend 设计wp7应用程序用户界面
- wp7 中Panorama控件 title 字体设置
- wp7 中Panorama控件 title 字体设置
- (转)Android:去除自定义dialog的title
- WP7开发应用程序的能力
- WP7入门篇(二)建立第一个wp7应用程序
- 自定义的Title
- 链接title自定义效果
- 自定义TITLE提示效果
- android 自定义title样式
- 自定义title实现
- [asp]让你知道codepage的重要
- EOF在Windows和Unix/Linux下的处理机制
- 编写高效的Android代码
- 我的vim配置
- 关于C++对象模型(下)
- 转新浪徐水峰博文-自定义WP7应用程序Title
- 使用DJ java Decomplier 将整个jar包反编译成源文件(转载)
- javascript把数字每隔三位加逗号分开,JavaScript Number Format - Add Commas
- pthread_kill 和 sigaction 函数
- C++中string相关函数用法
- 调用远程主机上的RMI服务时抛出java.rmi.ConnectException: Connection refused to host: 127.0.0.1异常原因及解决方案
- Groovy Goodness: Using ConfigSlurper with Configuration Scripts Groovy读取配置文件
- C# 委托与事件
- VS2010中的调试技巧 断点