当我取消注释内部枚举时,面板局部变量将变为错误。
我已经调试了几个小时了,我放弃了。这很奇怪,因为这正是Microsoft Band Documentation告诉我要做的事情。
我做错了什么?
这是我的代码:
// 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
}
}
答案 0 :(得分:0)
我明白了。我必须在私有方法之外键入内部枚举。谢谢@Michael Liu。