Windows Phone 8开发快速入门(七)
来源:互联网 发布:帝国时代2网络对战 编辑:程序博客网 时间:2024/05/08 06:51
主要内容:图块和通知(图块==磁贴)
Windows Phone 8的图块
图块:为用户提供最关注的信息。图块API支持应用创建和更新图块。
图块模板:翻转,图标,循环
翻转图块模板:小型图块不翻转FlipCycleTile*.png
循环图块模板:小型图块不循环FlipCycleTile*.png
图块大小:小型,中型,大型IconicTile*.png
主图块和次级图块(Create(Uri,ShellTileData)方法创建次级模块至开始屏幕)
定义应用的图块:双击WMAppMainifest.xml-->Application UI
本地图块
更新使用ShellTileSchedule
创建图块
Public static void SetTile(RecipeDataItem item,string NavSource)
{
FlipTileData tileData=new FlipTileData()
{
//Front square data
Title=item.Title,
BackgroundImage=newUri("ms-appx:///background1.png",UriKind.Relative),
SmallBackgroundImage=newUri("ms-appx:///smallbackground1.png",UriKind.Relative),
//Back square data
BackTitle=item.Title,
BackContent=item.Ingredients,
BackBackgroundImage=newUri("ms-app0x:///background1.png",UriKind.Relative),
//Wide tile data
WideBackgroundImage=newUri("ms-appx:///widebackground1.png",UriKind.Relative),
WideBackBackgroundImage=newUri("ms-appx:///widebackbackground1.png",Urikind.Relative),
WideBackContent=item.Direction
};
//Create Tile and pin it to Start. Causes a navigation to start anda deactivation of our application
ShellTile.Create(newUri("/RecipePage.xaml?DefaultTitle=FromTile",UriKind.Relative),titleData,true);
}
使用ShellTileSchedule更新图块
更新图块
//Find the Tile we want to update.
ShellTileTileToFind=ShellTile.ActiveTiles.FirstOrDefault(x=>x.NavigationUri.ToString().Contains("DefaultTitle=FromTile"));
//If the Tile was found , then updata the Title.
If(TileToFind!=null)
{
FlipTileData NewTileData=new FlipTileData
{
Title=textBoxTitle.Text
};
TileToFind.Update(NewTileData);
Updating the Application Tile
Public static void UpdateMainTile(RecipeDataGroup group)
{
//Get application's main tile-application tile always first item inthe ActiveTiles collection whether it is pinned or not
Var mainTile=ShellTile.ActiveTiles.FirstOrDefault();
IconicTileData tileDaa=new IconicTileData()
{
Count=group.RecipesCount,
BackgroundColor=Color.FromArgb(255,195,61,39),
Title="Contoso Cookbooks",
IconImage=newUri("ms-appx:///local/shared/shellcontent/newMedLogo.png",UriKind.RelativeOrAbsolute),
SmallIconImage=newUri("ms-appx:///local/shared/shellcontent/newSmlLogo.pg",UriKind.RelativeOrAbsolute),
WideContent1="Recent activity:",
WideContent2="Browsed"+group.Title+"group",
WideContent3="with totalof"+group.RecipesCount+"recipes"
};
mainTile.Updata(tileData);
}
后台代理更新图块
可以使用ShellTileSchedule来更新应用图块背景图像和次要图块
Windows Phone 8的锁定屏幕通知
创建锁定屏幕图标
在XML编辑器中修改WMAppManifest.xml
<Tokens>
<PrimaryToken TokenId="PhoneApp4Token"TaskName="_default">
<TemplateFlip>
……
<DeviceLockImageURI>MyLockIcon.png</DeviceLockImageURI>
</TemplateFlip>
</PrimaryToken>
</Tokens>
更改应用程序清单
在XML编辑器中修改WMAppManifest.xml
<Extensions>
<ExtensionExtensionName="LockScreen_Notification_IconCount"ConsumerID="{111DFF24-AA15-4A96-8006-2BFF122084f}"TaskID="_default"/>
<ExtensionExtensionName="LockScreen_Notification_TextField"ConsumerID="{111DFF24-AA15-4A96-8006-2BFF122084f}"TaskID="_default"/>
</Extensions>
在模拟器仪表板中测试
VS-->Tools-->SimulationDashboard-->Lock Screen
Windows Phone 8的锁定屏幕背影
更新应用程序清单文件
在XML编辑器中修改WMAppManifest.xml、
<Extensions>
<ExtensionExtensionName="LockScreen_Background"ConsumerID="{111DFF24-AA15-4A96-8006-2BFF122084f}"TaskID="_default"/>
</Extensions>
添加代码以更改锁定屏幕背景
Private async void lockHelper(Uri backgroundImageUri,stringbackgroundAction)
{
Try
{
//If you're not the provider, this call will prompt the user forpermission.
//Calling RequestAccdessAsync from a background agent is notallowed.
Var op=await LockScreenManager.RequestAccessAsync();
//Check the status to make sure we were given permission.
Boo isProvider=LockScreenManager.IsProvidedByCurrentApplication;
If(isProvider)
{
//Do the update.
Windows.Phone.System.UserProfile.LockScreen.SetImageUri(backgroundImageUri);
System.Diagnostics.Debug.WriteLine("New current image set to{0}",backgroundImageUri.ToString());
}
Else
{
MessxageBox.Show("You said no, so I can't update yourbackground.");
}
}
Catch(System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
//If you're not the provider, this call will prompt the user forpermission.
//Calling RequestAccessAsync from a background agent is not allowed.
Var op=await LockScreenManager.RequestAccessAsync();
访问本地文件
应用程序的图片,采用ms-appx:///
Uri imageUri=newUri("ms-appx:///background1.png",UriKind.RelativeOrAbsolute);
LockScreen.SetImageUri(imageUri);
本地文件夹中的图片,采用ms-appdata:///local/shared/shellcontent
Uri imageUri=newUri("ms-appdata:///local/shared/shellcontent/background2.png",UriKind.RelativeOrAbsolute);
LockScreen.SetImageUri(imageUri);
- Windows Phone 8开发快速入门(七)
- Windows Phone 8 开发快速入门
- Windows Phone 8 开发快速入门(八)
- Windows Phone 8开发入门(六)
- Windows Phone 8开发入门(五)
- 国外Windows Phone 7开发教程(四天快速入门)
- Windows Phone 开发学习笔记(七) Hello Windows Phone之有始有终
- Windows Phone 7开发入门
- Windows Phone开发入门基础
- xFace的快速入门--windows phone
- Windows phone 8开发入门:使用Pivot和Panorama控件
- Windows phone开发入门:技术资料索引库
- 奇怪的Windows Phone入门开发日志
- Windows Phone 7 入门指南(Windows Phone 8已经发布,不过还有一些借鉴意义)
- Windows Phone开发学习之七——IDE介绍
- Windows Phone 8 开发笔记
- Windows Phone 8 开发笔记
- Windows Phone 8开发链接
- Oracle的select语句用start with...connect by prior子句实现递归查询
- SSH下mysql中文乱码问题
- 使用Def文件导出Dll文件
- 编程之美之买书问题
- Lake Counting --- 深度优先搜索
- Windows Phone 8开发快速入门(七)
- 统计学里“P”的故事:蚊子、皇帝的新衣和不育的风流才子
- Hibernate 缓存机制
- Mysql 自动备份与恢复
- STL--map用法
- 小饭桌沙盘演戏商战-老友记成长
- SecureCRT图形界面(通过设置调用Xmanager - Passive程序)
- maven创建struts2的web工程启动时报过滤器找不到错误
- 一篇SSH框架的应用介绍