我正在使用 UWP 开发 Microsoft Band 2 应用程序,因为我尝试从应用程序访问现有的 Tile 以更新 Tile PageLayout 背景。 我编写了以下用于创建图 block 的代码
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
}
}
以下是我尝试更新图 block 但不起作用的代码。
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)
{
}
}
pageLayout.Root = panel 之后;代码我无法找到如何将更改发送回 Band Tile。
任何人都可以帮助我如何更新 Tile PageLayout 背景颜色。
最佳答案
页面布局本身是静态的;一旦添加了图 block ,它们就无法更改(除了删除然后重新添加图 block 之外)。这个想法是,您可以更新页面实例(具有给定布局)的内容(例如文本)。 Band SDK Documentation 第 8.7 节描述可以在给定 Page 实例中更新的内容。
对于您的场景,应用程序需要允许用户选择最多 5 种可以在您的图 block 中使用的颜色在任何给定时间,然后定义 5 个页面布局,每个页面布局使用以下之一那些颜色。 (一个图 block 最多可以有 5 个页面布局。)然后您可以创建 5 个页面实例,每个定义的布局一个,以创建一个图 block ,其中每种颜色都有一个页面。如果用户想要更改颜色混合,则应用程序将需要删除并重新添加具有一组新页面布局的图 block 。
关于c# - 从 UWP 手机应用更新现有的 Microsoft Band Tile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36351169/