2016-04-01 55 views
2

我正在开发使用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背景颜色。

回答

3

页面布局本身是静态的;一旦添加了一个Tile,它们就不能被改变(除去并重新添加Tile)。这个想法是,你更新页面实例的内容(例如文本)(使用给定的布局)。 Band SDK Documentation的第8.7节描述了可在给定页面实例内更新的内容。

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

+0

感谢您的建议菲尔。 – narendramacha