随笔 - 55  文章 - 15  trackbacks - 0
<2013年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜


31 Days of Windows 8 -- Live Tiles:http://www.jeffblankenburg.com/2012/11/09/31-days-of-windows-8-day-9-live-tiles/
MSDN--创建瓷贴和锁屏 : http://msdn.microsoft.com/library/windows/apps/Hh465377

创建瓷贴的步骤:

 1. 命名空间:
 
using namespace Windows::UI::Notifications;
using namespace Windows::Data::Xml::Dom;

2. 选取模板   http://msdn.microsoft.com/zh-CN/library/windows/apps/xaml/windows.ui.notifications.tiletemplatetype
3. 设置模板中的属性,最好将WideTile和SquareTile合并在一起,这样不论你的Tile是哪种形态都有动态效果。
4. 更新Tile

下面是一个完整步骤: 
 1using namespace Windows::UI::Notifications; // Notification命名空间
 2using namespace Windows::Data::Xml::Dom; // DOM标准函数命名空间
 3namespace WFC = Windows::Foundation::Collections;
 4
 5XmlDocument^ tileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileWideImageAndText01);//获得模板
 6
 7XmlNodeList^ tileTextAttributes = tileXml->GetElementsByTagName("text");
 8tileTextAttributes->Item(0)->InnerText = "Hello World! My very own tile notification";//设置text属性
 9
10XmlNodeList^ tileImageAttributes = tileXml->GetElementsByTagName("image");
11static_cast<XmlElement^>(tileImageAttributes->Item(0))->SetAttribute("src""ms-appx:///images/redWide.png");  //此处如果要使用Assets中的图片的话,直接用SetAttribute("src","Tile.png");                      
12static_cast<XmlElement^>(tileImageAttributes->Item(0))->SetAttribute("alt""red graphic");// 设置image属性
13
14XmlDocument^ squareTileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquareText04); //获得方形模板
15XmlNodeList^ squareTileTextAttributes = squareTileXml->GetElementsByTagName("text");
16squareTileTextAttributes->Item(0)->AppendChild(squareTileXml->CreateTextNode("Hello World! My very own tile notification"));//设置text属性
17IXmlNode^ node = tileXml->ImportNode(squareTileXml->GetElementsByTagName("binding")->GetAt(0), true);
18tileXml->GetElementsByTagName("visual")->Item(0)->AppendChild(node);//将方形模板插入Wide模板
19
20TileNotification^ tileNotification = ref new TileNotification(tileXml);
21
22int seconds = 10;
23auto cal = ref new Windows::Globalization::Calendar();
24cal->AddSeconds(seconds);    
25tileNotification->ExpirationTime = cal->GetDateTime();//设置消失时间
26
27TileUpdateManager::CreateTileUpdaterForApplication()->Update(tileNotification); //显示Tile
28
29

也可以使用XML文件设置属性:
 1    // create a string with the tile template xml
 2    auto tileXmlString = "<tile>"
 3        + "<visual>"
 4        + "<binding template='TileWideText03'>"
 5        + "<text id='1'>Hello World! My very own tile notification</text>"
 6        + "</binding>"
 7        + "<binding template='TileSquareText04'>"
 8        + "<text id='1'>Hello World! My very own tile notification</text>"
 9        + "</binding>"
10        + "</visual>"
11        + "</tile>";
12
13    // create a DOM
14    auto tileDOM = ref new Windows::Data::Xml::Dom::XmlDocument();
15
16    // load the xml string into the DOM, catching any invalid xml characters 
17    tileDOM->LoadXml(tileXmlString);
18
19    // create a tile notification
20    auto tile = ref new TileNotification(tileDOM);
21
22    // Send the notification to the app's application tile
23    TileUpdateManager::CreateTileUpdaterForApplication()->Update(tile);
24
25    OutputTextBlock->Text = tileDOM->GetXml();

清理瓷贴
    TileUpdateManager::CreateTileUpdaterForApplication()->Clear();

使用瓷贴队列
    一个应用程序中最多能使用5个瓷贴,如果开启了瓷贴队列,会按照先后顺序放入队列中。之后TileNotification的显示时间和显示顺序将不受程序控制,这时的控制权是在系统手中的。
    为了便于控制瓷贴的显示,我们一般给瓷贴一个Tag用于辨识,当新的瓷贴的Tag与旧瓷贴的Tag相同时,旧瓷贴被新瓷贴代替。如果不同,队列头上的瓷贴被踢出队列。
    最近的瓷贴总是被立即显示。另外,当队列中已经有了5个瓷贴的时候,其中一个使用了Expirate,那么当这个瓷贴消失之后,将不再在队列中,也不会再显示它了。
    使用瓷贴队列的方法是:
     TileUpdateManager::CreateTileUpdaterForApplication()->EnableNotificationQueue(true);
    禁止瓷贴队列的方法:
     TileUpdateManager::CreateTileUpdaterForApplication()->EnableNotificationQueue(false);

瓷贴的图片问题
      用于Tile的图片不能大于200K,像素不能大于1024*1024,但是我们的Tile最大是310*150,所以我们在使用图片的时候要考虑到大小问题。
posted on 2013-01-03 14:31 Dino-Tech 阅读(1436) 评论(1)  编辑 收藏 引用 所属分类: Windows 8

FeedBack:
# re: Dino Windows 8 学习笔记(十二) - 动态瓷贴 2013-01-04 00:46 custom research papers
Very ncie good spot s oncie great!  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理