主要內容:圖塊和通知(圖塊==磁貼)
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);