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);

 

0 0
原创粉丝点击