ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

c# – 如何在页面中创建Microsoft Band自定义图标 – Windows UWP

2019-07-06 10:05:28  阅读:128  来源: 互联网

标签:c visual-studio win-universal-app microsoft-band


我一直在尝试将自定义图标添加到填充面板中.

documentation中,第8.5节中有一些信息,SDK中的示例表明开发人员可以自定义磁贴的大图标和小图标.但是,没有明确的示例说明如何在页面上的图块中为自定义图标执行此操作.

进一步搜索,我发现Visual Studio有一个新的Microsoft Band Tile Design Plugin.这似乎说明了我想要做的事情但是当我尝试使用代码生成部分(页面中间的一半)中指定的代码时,我无法加载我使用设计器创建的简单自定义布局:

enter image description here

以下是链接自定义布局的代码,如Tile Design Plugin页面所述:

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);
            }

错误日志如下:

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.

我在网上找不到任何错误的细节,但我认为它是因为我使用过:

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

而不是将customtiledesign.Data.All传递给… SetPagesAsync()方法.

这是因为没有重载形式的SetPageAsync将PageElementData []作为参数.

解决方法:

图标在图块布局上不可见的原因是因为索引1传递给构造函数:PageData pd = new PageData(tileGuid,1,customtiledesign.Data.All);.它应该是0.

即您的磁贴可能有多个布局,您的调用是为第二个不存在的布局设置数据.对于您添加的唯一布局,索引为0.

当你成功的时候,你可能会发现你的瓷砖没有好的图标.这是因为在调用ToBandIcon之前,smallIconBitmap和tileIconBitmap需要一些好的源代码.示例提供以下用于加载图标的代码.

    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();
        }
    }

标签:c,visual-studio,win-universal-app,microsoft-band
来源: https://codeday.me/bug/20190706/1396258.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有