C# 内部枚举正在破坏我的代码

C# 内部枚举正在破坏我的代码,c#,microsoft-band,C#,Microsoft Band,当我取消对内部枚举的注释时,panel局部变量会变成一个错误 我已经调试了几个小时了,我放弃了。这很奇怪,因为这正是Microsoft Band文档告诉我要做的 我做错了什么 这是我的代码: // create a new Guid for the tile Guid tileGuid = Guid.NewGuid(); // create a new tile with a new Guid BandTile tile = new BandTi

当我取消对内部枚举的注释时,panel局部变量会变成一个错误

我已经调试了几个小时了,我放弃了。这很奇怪,因为这正是Microsoft Band文档告诉我要做的

我做错了什么

这是我的代码:

// 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 = "Maps",
            // set the icons
            SmallIcon = smallIcon,
            TileIcon = tileIcon
        };

        // create a scrollable vertical panel that will hold 2 text messages
        ScrollFlowPanel panel = new ScrollFlowPanel
        {
            Rect = new PageRect(0, 0, 245, 102),
            Orientation = FlowPanelOrientation.Vertical,
            ColorSource = ElementColorSource.BandBase
        };

        // Define symbolic constants for indices to each layout that
        // the tile  has. The index of the first layout is 0. Since at
        // most 5 layouts are allowed, the max index value is 4.
        //        internal enum TileLayoutIndex
        //{
        //    MessagesLayout = 0
        //}

        // Define symbolic constants to uniquely (in MessagesLayout)
        // identify each of the elements of our layout
        // that contain content that the app will set
        // (that is, these Ids will be used when calling APIs
        // to set the page content)
    //            internal enum TileMessagesLayoutElementId : short
    //{
    //    Message1 = 1, // Id for the 1st message text block
    //    Message2 = 2, // Id for the 2nd message text block
    //}


    // add the text block to contain the first message
    panel.Elements.Add(
            new WrappedTextBlock
            {
                ElementId = (short)TileMessagesLayoutElementId.Message1,
                Rect = new PageRect(0, 0, 245, 102),
            // left, top, right, bottom margins
            Margins = new Margins(15, 0, 15, 0),
                Color = new BandColor(0xFF, 0xFF, 0xFF),
                Font = WrappedTextBlockFont.Small
            }

            );

// add the text block to contain the second message
        panel.Elements.Add(
        new WrappedTextBlock
        {
            ElementId = (short)TileMessagesLayoutElementId.Message2,
            Rect = new PageRect(0, 0, 245, 102),
            // left, top, right, bottom margins
            Margins = new Margins(15, 0, 15, 0),
            Color = new BandColor(0xFF, 0xFF, 0xFF),
            Font = WrappedTextBlockFont.Small
        }

        );

        // create the page layout
        PageLayout layout = new PageLayout(panel);

        try
        {
            // add the layout to the tile
            tile.PageLayouts.Add(layout);
        }
        catch (BandException ex)
        {
            // handle an error adding the layout
        }

        // Prerequisite: bandClient has successfully connected to a Band

        using (IBandClient bandClient = await
        BandClientManager.Instance.ConnectAsync(pairedBands[0]))

            try
        {
            // add the tile to the Band
            if (await bandClient.TileManager.AddTileAsync(tile))
            {
                // tile was successfully added,
                // can proceed to set tile content with SetPagesAsync
            }
            else
            {
                // tile failed to be added, handle error
            }
        }
        catch (BandException ex)
        {
            // handle a Band connection exception
        }
    }

    private async void button_Click(object sender, RoutedEventArgs e)
    {
        IBandInfo[] pairedBands = await
        BandClientManager.Instance.GetBandsAsync();
        using (IBandClient bandClient = await
        BandClientManager.Instance.ConnectAsync(pairedBands[0]))

            try
            {
                // get the current set of tiles
                IEnumerable<BandTile> tiles = await
            bandClient.TileManager.GetTilesAsync();

                foreach (var t in tiles)
                {
                    // remove the tile from the Band
                    if (await bandClient.TileManager.RemoveTileAsync(t))
                    {
                        // do work if the tile was successfully removed
                    }
                }
            }
            catch (BandException ex)
            {
                // handle a Band connection exception
            }
    }
//为磁贴创建新的Guid
Guid tileGuid=Guid.NewGuid();
//使用新Guid创建新磁贴
BandTile tile=新的BandTile(tileGuid)
{
//启用标记(未读邮件的计数)
IsBadgingEnabled=true,
//设定名称
Name=“Maps”,
//设置图标
SmallIcon=SmallIcon,
TileIcon=TileIcon
};
//创建一个可滚动的垂直面板,可容纳2条文本消息
ScrollFlowPanel=新的ScrollFlowPanel
{
Rect=新页面Rect(0,0,245,102),
方向=流动面板方向。垂直,
ColorSource=ElementColorSource.BandBase
};
//为每个布局的索引定义符号常量
//这块瓷砖已经贴好了。第一个布局的索引为0。从
//最多允许5个布局,最大索引值为4。
//内部枚举TileLayoutIndex
//{
//MessagesLayout=0
//}
//将符号常量定义为唯一(在MessagesLayout中)
//确定布局的每个元素
//包含应用程序将设置的内容的
//(也就是说,调用API时将使用这些ID
//设置页面内容的步骤)
//内部枚举TileMessageLayoutElementId:短
//{
//Message1=1,//第一个消息文本块的Id
//Message2=2,//第二个消息文本块的Id
//}
//添加文本块以包含第一条消息
panel.Elements.Add(
新WrappedTextBlock
{
ElementId=(短)TileMessageLayoutElementId.Message1,
Rect=新页面Rect(0,0,245,102),
//左、上、右、下页边距
保证金=新保证金(15,0,15,0),
颜色=新带颜色(0xFF,0xFF,0xFF),
Font=WrappedTextBlockFont.Small
}
);
//添加文本块以包含第二条消息
panel.Elements.Add(
新WrappedTextBlock
{
ElementId=(短)TileMessageLayoutElementId.Message2,
Rect=新页面Rect(0,0,245,102),
//左、上、右、下页边距
保证金=新保证金(15,0,15,0),
颜色=新带颜色(0xFF,0xFF,0xFF),
Font=WrappedTextBlockFont.Small
}
);
//创建页面布局
PageLayout=新的PageLayout(面板);
尝试
{
//将布局添加到互动程序
tile.PageLayouts.Add(布局);
}
捕获(带异常)
{
//处理添加布局时出现的错误
}
//先决条件:bandClient已成功连接到频带
使用(IBandClient-bandClient=wait
BandClientManager.Instance.ConnectAsync(pairedBands[0]))
尝试
{
//将平铺添加到条带
if(等待bandClient.TileManager.AddTileAsync(平铺))
{
//已成功添加磁贴,
//可以继续使用SetPagesAsync设置磁贴内容
}
其他的
{
//无法添加磁贴,处理错误
}
}
捕获(带异常)
{
//处理频带连接异常
}
}
专用异步无效按钮\u单击(对象发送方,路由目标)
{
IBandInfo[]pairedBands=等待
实例。GetBandsAsync();
使用(IBandClient-bandClient=wait
BandClientManager.Instance.ConnectAsync(pairedBands[0]))
尝试
{
//获取当前的分幅集
IEnumerable tiles=等待
bandClient.TileManager.GetTilesAsync();
foreach(瓦片中的var t)
{
//从带子上取下瓷砖
if(等待bandClient.TileManager.RemoveTileAsync(t))
{
//如果瓷砖已成功移除,请执行此操作
}
}
}
捕获(带异常)
{
//处理频带连接异常
}
}

我想出来了。我必须在私有方法之外键入内部枚举。谢谢@Michael Liu。

您不能在方法中声明枚举。将枚举移到方法外部。方法外部的位置?按钮法?没关系。我想出来了。