C# MS Band SDK-未调用按钮按下事件处理程序

C# MS Band SDK-未调用按钮按下事件处理程序,c#,microsoft-band,C#,Microsoft Band,我已经在我的应用程序中用一个按钮设置了我的互动程序和页面布局,但当我按下按钮时,不会调用事件处理程序。我尝试使用tile open事件处理程序,但也不起作用。我的代码如下: private async void OnConnectToBand() { IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync(); try { using (IBandClient b

我已经在我的应用程序中用一个按钮设置了我的互动程序和页面布局,但当我按下按钮时,不会调用事件处理程序。我尝试使用tile open事件处理程序,但也不起作用。我的代码如下:

private async void OnConnectToBand()
{

    IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

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

        //add tile, create page layout with button and add content with button

        //subscribe to listeners

        bandClient.TileManager.TileButtonPressed += EventHandler_TileButtonPressed;

        // Start listening for events 
        bandClient.TileManager.StartReadingsAsync();
        }
    }
    catch(BandException ex)
    { 
        //handle a Band connection exception 
    } 
}

void EventHandler_TileButtonPressed(object sender, BandTileEventArgs<IBandTileButtonPressedEvent> e)
{ 
// handle event
}
编译器说Button没有接受2个参数的构造函数

我假设示例代码中有一个错误,并将其更改为TextButtonData,这可以很好地编译,但现在我想知道这是否就是事件处理程序无法工作的原因?代码是:

PageData pageContent = new PageData( 
      pageGuid, 
      0, // index of our (only) layout 
      new TextButtonData(
         (short)TilePageElementId.Button_PushMe, "Push"));

有什么想法吗?

很高兴看到有人在MS乐队发展。。。。以下是一些讨论OnConnectToBand及其设置的链接

void EventHandler_TileButtonPressed(object sender,
BandTileEventArgs<IBandTileButtonPressedEvent> e)
{
 // This method is called when the user presses the
 // button in our tile’s layout.
 //
 // e.TileEvent.TileId is the tile’s Guid.
 // e.TileEvent.Timestamp is the DateTimeOffset of the event.
 // e.TileEvent.PageId is the Guid of our page with the button.
 // e.TileEvent.ElementId is the value assigned to the button
 // in our layout (i.e.,
 // TilePageElementId.Button_PushMe).
 //
 // handle the event
 }
void EventHandler_tileButton按下(对象发送方,
BandTileEventArgs e)
{
//当用户按下
//按钮在我们的瓷砖的布局。
//
//e.TileEvent.TileId是磁贴的Guid。
//e.TileEvent.Timestamp是事件的DateTimeOffset。
//e.TileEvent.PageId是带有按钮的页面的Guid。
//e.TileEvent.ElementId是分配给按钮的值
//在我们的布局中(即。,
//TilePageElementId.按钮(按我)。
//
//处理事件
}
第9节-处理自定义事件

讨论添加、单击和删除平铺

尝试添加一个对话框(下面是windows代码,适用于ios或android,请参阅上述手册)以响应事件(在上面的代码中,事件处理程序中没有任何内容?这是为了查看它是否真的起作用

using Microsoft.Band.Notifications;

try
{
 // send a dialog to the Band for one of our tiles
 await bandClient.NotificationManager.ShowDialogAsync(tileGuid,
"Dialog title", "Dialog body");
}
catch (BandException ex)
{
// handle a Band connection exception
}

只有当您有一个活动的
IBandClient
实例(即,与Band的活动连接)时,您才能从Band接收事件。在上面的代码中,由于使用了
using(){},在调用
startReadingAsync()
后,会立即释放
bandClient
实例
block。当处置
IBandClient
实例时,它会导致应用程序断开与频带的连接


您需要在希望接收事件的时间段内保留
IBandClient
实例,并在该时间段后处理该实例。

是的,我在偶数处理程序中有一条弹出消息要测试,但我仍在使用调试器,并且知道它不会到达那里。感谢链接,因为它将帮助我测试还有:)但是对于事件处理程序,我使用的是来自SDK文档的信息。我刚刚在我的原始帖子中发布了一个更新,因为我认为我做错了什么,但我认为doco的代码中有一个错误。您能提供更多的OnConnectToBand()方法吗?您的简短代码段忽略了一些可能指向问题原因的详细信息(例如IBandClient连接的生存期)。已将其添加到上述代码中。我在SDK文档中没有看到任何关于连接生存期的内容,所以没有任何关于它的内容,所以可能这就是问题所在?谢谢,这就是问题所在。doco把它放在一个使用块中,但我能理解为什么它不起作用。如果我想一直监听事件直到它们退出,我应该在TileClose事件处理程序中处理该实例吗?我应该调用什么来处理该实例?在BandClientManager.Instance.IBandClient继承IDisposable中找不到任何类似的内容(这就是为什么可以在using(){}块中使用它)。监听完事件后,只需在客户端实例上调用Dispose()方法。
using Microsoft.Band.Notifications;

try
{
 // send a dialog to the Band for one of our tiles
 await bandClient.NotificationManager.ShowDialogAsync(tileGuid,
"Dialog title", "Dialog body");
}
catch (BandException ex)
{
// handle a Band connection exception
}