我正在開發使用UWP的Microsoft Band 2應用程序,因爲我試圖從應用程序訪問現有的Tile以更新Tile PageLayout背景。 我已經寫了下面的代碼創建瓷磚從UWP手機應用程序更新現有的Microsoft Band Tile
IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Count() > 0)
{
try
{
using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
// do work after successful connect
// get the current set of tiles
IEnumerable<BandTile> tiles = await bandClient.TileManager.GetTilesAsync();
if (tiles.Count() == 0)
{
int tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();
if (tileCapacity > 0)
{
// create a new Guid for the tile
Guid tileGuid = Guid.NewGuid();
// create a new tile with a new Guid
BandTile tile = new BandTile(tileGuid)
{
// enable badging (the count of unread messages)
// IsBadgingEnabled = true,
// set the name
Name = "Torch Tile",
TileIcon = await LoadIcon("ms-appx:///Assets/Electric Bulb.png"),
SmallIcon = await LoadIcon("ms-appx:///Assets/Torchsmaltile.png")
};
var panel = new FilledPanel
{
//ElementId = 0,
Rect = new PageRect(0, 0, 260, 128),
BackgroundColor = bandcolor
};
var layout = new PageLayout(panel);
tile.PageLayouts.Add(layout);
try
{
// add the tile to the Band
if (await bandClient.TileManager.AddTileAsync(tile))
{
List<PageData> pageDataArray = new List<PageData>();
pageDataArray.Add(new PageData(pageguid, 0, new FilledButtonData(0, Colors.Transparent.ToBandColor())));
await bandClient.TileManager.SetPagesAsync(
tileGuid, pageDataArray);
}
}
catch (BandException ex)
{
// handle a Band connection exception }
}
}
}
}
}
catch (BandException e)
{
// handle BandException
}
}
以下是我試圖更新塊,但不工作的代碼。
IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Count() > 0)
{
try
{
using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
// do work after successful connect
// get the current set of tiles
IEnumerable<BandTile> tiles = await bandClient.TileManager.GetTilesAsync();
if (tiles.Count() > 0)
{
foreach (var tile in tiles)
{
foreach (var pageLayout in tile.PageLayouts)
{
var panel = pageLayout.Root as FilledPanel;
panel.BackgroundColor = Colors.Green.ToBandColor();
pageLayout.Root = panel;
}
}
}
}
}
catch (Exception ex)
{
}
}
after pageLayout.Root = panel;代碼我無法找到如何將更改發送回Band Tile。
任何人都可以幫助我如何更新Tile PageLayout背景顏色。
感謝您的建議菲爾。 – narendramacha