如何使用VB获取messagedialog以在Windows应用商店应用中调用另一个子例程?

时间:2013-09-03 14:28:42

标签: vb.net windows-runtime windows-store-apps

这是我到目前为止所做的:

Private Async Sub cmdAppBarLogout_Click(sender As Object, e As RoutedEventArgs) Handles cmdAppBarLogout.Click
Dim message As New MessageDialog("Are you sure you want to logout?", "Logout confirmation")    

        message.Commands.Add(New UICommand("Yes"))

        message.Commands.Add(New UICommand("No"))    

        Await message.ShowAsync
End Sub


Private Sub Logout()
        session.StaffInfo = Nothing
        Frame.Navigate(GetType(Login))
End Sub

当用户点击“是”按钮时,我希望调用Logout Sub,但我不知道如何执行此操作。我发现了许多与C#和C ++相关的例子,尽管VB似乎并不存在。请帮忙。

我知道“message.Commands.Add(新的UICommand(”函数有额外的参数,但我不知道如何正确使用它们。

2 个答案:

答案 0 :(得分:0)

用此更新您的代码。

message.Commands.Add(New UICommand("Yes", AddressOf Logout))

查看MSDN sample

答案 1 :(得分:0)

UICommand具有多个构造函数,可以在调用命令时指定回调处理程序。您提供的代码不使用指定此类处理程序的构造函数。

我在下面的代码中包含了如何在UICommand中指定回调处理程序的代码。每个命令都可以有自己的方法,共享相同的方法,或根本没有方法。

...
    message.Commands.Add(New UICommand("Yes", AddressOf Me.CommandInvokedHandler))
    message.Commands.Add(New UICommand("No"))
...

Private Sub CommandInvokedHandler(command As IUICommand)
    ' Run the appropriate code based on the callback here.
    ' If this handler is shared between multiple commands, use command.Label
    ' or command.Id to determine which command is being invoked.
    Logout
End Sub