Reputation: 570
I am developing Microsoft Band 2 app using UWP, In that I am trying to access the existing Tile from the app to Update the Tile PageLayout background. I have written the below code for creating 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
}
}
The following is the code I am trying to Update Tile but not working.
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; code I am not able to find how to send the changes back to Band Tile.
Can anyone help me how to update the Tile PageLayout background color.
Upvotes: 2
Views: 125
Reputation: 2016
Page layouts themselves are static; once a Tile has been added they cannot be changed (outside of removing and then re-adding the Tile). The idea is that you instead update the contents (e.g. text) of an instance of a Page (with a given layout). Section 8.7 of the Band SDK Documentation describes the content that can be updated within a given Page instance.
For your scenario, the application needs to allow the user to choose a maximum of 5 colors that can be used within your Tile at any given time, then define 5 Page layouts that each use one of those colors. (A Tile can have a maximum of 5 Page layouts.) Then you can create 5 page instances, one for each defined layout, to create a Tile that has a Page for each color. If the user wants to change the mix of colors, then the application will need to remove and then re-add the Tile with a new set of Page layouts.
Upvotes: 3