【问题标题】:Updating an existing Microsoft Band Tile from UWP phone app从 UWP 手机应用更新现有的 Microsoft Band Tile
【发布时间】:2016-04-02 01:38:23
【问题描述】:

我正在使用 UWP 开发 Microsoft Band 2 应用程序,因为我正在尝试从应用程序访问现有的 Tile 以更新 Tile PageLayout 背景。 我已经编写了以下用于创建图块的代码

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)
                {

                }
            }

在 pageLayout.Root = 面板之后;代码我无法找到如何将更改发送回 Band Tile。

谁能帮助我如何更新 Tile PageLayout 背景颜色。

【问题讨论】:

    标签: c# win-universal-app microsoft-band


    【解决方案1】:

    页面布局本身是静态的;一旦添加了 Tile,它们就无法更改(除了删除然后重新添加 Tile)。这个想法是您改为更新页面实例(具有给定布局)的内容(例如文本)。 Band SDK Documentation 的第 8.7 节描述了可以在给定 Page 实例中更新的内容。

    对于您的场景,应用程序需要允许用户选择最多 5 种颜色,在任何给定时间可以在您的 Tile 中使用,然后定义 5 个页面布局,每个布局使用一种那些颜色。 (一个 Tile 最多可以有 5 个页面布局。)然后您可以创建 5 个页面实例,每个定义的布局一个,以创建一个具有每种颜色的页面的 Tile。如果用户想要更改颜色组合,则应用程序需要删除并重新添加具有一组新页面布局的 Tile。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多