How to create custom Microsoft Band badges inside pages - Windows UWP

I am trying to add a custom icon to a populated panel.

The documentation has information on this in Section 8.5, and the examples in the SDK demonstrate that a developer can customize large and small tile icons. However, there is no clear example of how to do this for a custom icon inside a tile on a page.

Looking further, I discovered that a new Design Platform for the Microsoft Toolbar has appeared for Visual Studio . This seems to demonstrate what I wanted to do, however, while trying to use the code specified in the "Generate Code" section (halfway down the page), I was unable to load a simple custom layout that I created using the constructor:

enter image description here

Here is the code that links the custom layout as described on the Tile Design plugin page:

try
            {
                // create a new Guid for the tile
                tileGuid = Guid.NewGuid();
                // create a new tile with a new Guid
                WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
                BandIcon smallIcon = smallIconBitmap.ToBandIcon();
                WriteableBitmap tileIconBitmap = new WriteableBitmap(48, 48);
                BandIcon tileIcon = tileIconBitmap.ToBandIcon();
                BandTile tile = new BandTile(tileGuid)
                {
                    // Name of the Tile
                    Name = "MyTile",
                    // Create the small and tile icons from writable bitmaps.
                    // Small icons are 24x24 pixels.
                    SmallIcon = smallIcon,
                    // Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels
                    // for Microsoft Band 2.
                    TileIcon = tileIcon
                };
                var customtiledesign = new SentimentFeedbackLayout();
                tile.PageLayouts.Add(customtiledesign.Layout);
                await customtiledesign.LoadIconsAsync(tile);

                if (await bandClient.TileManager.AddTileAsync(tile))
                {
                    Debug.WriteLine("New tile added | GUID: " + tileGuid);
                }

                PageData pd = new PageData(tileGuid, 1, customtiledesign.Data.All);

                if (await bandClient.TileManager.SetPagesAsync(tileGuid, pd))
                {
                    Debug.WriteLine("Added pages");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

The error log is as follows:

Band Connected : MSFT Band 2 bb:bc
Version: 2.0.4215.0, Hardware: 26
Band - Removing all Tiles
Removed tile: MyTile
New tile added | GUID: 4803e0fe-2da2-4efb-9389-bde3a9289d30
Exception thrown: 'Microsoft.Band.BandOperationException' in mscorlib.ni.dll
Error Device status code: 0xA0CC006A received.

I could not find any details about the error on the Internet, but I think this is because I used:

 PageData pd = new PageData(tileGuid, 1, customtiledesign.Data.All);

Instead of passing customtiledesign.Data.All to the ... SetPagesAsync () method.

This happened because there was no overloaded form of SetPageAsync, which took the PageElementData [] parameter as an argument.

+4
2

, , 1, : PageData pd = new PageData (tileGuid, 1, customtiledesign.Data.All);, 0.

.. , . , , 0.

, , , , . , smallIconBitmap tileIconBitmap ToBandIcon. .

    private async Task<BandIcon> LoadIcon(string uri)
    {
        StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

        using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
        {
            WriteableBitmap bitmap = new WriteableBitmap(1, 1);
            await bitmap.SetSourceAsync(fileStream);
            return bitmap.ToBandIcon();
        }
    }
+1

, LoadIconsAsync AddTileAsync ( , ). , , , . 2 . . , , , MSDN. . . .

, , , , MSDN, . AddTilesAsync LoadIconsAsync

1.if( bandClient.TileManager.AddTileAsync(tile))

  1. {

  2. ...

  3. }

  4. customLayout.LoadIconsAsync(tile);

, GetBandsAsync True Windows Phone 10 , IBackgroundTask. , , .

0

All Articles