按钮从我的视图绑定到我的viewmodel,如下所示:
<Button Text="Report error" Command="{Binding NewErrorCommand}" />
public Command NewErrorCommand
{
get
{
return _newErrorCommand ?? (_newErrorCommand = new Command(ExecuteNewErrorCommand, CanNewErrorCommand));
}
}
private bool CanNewErrorCommand(object arg)
{
return true;
}
private async void ExecuteNewErrorCommand(object obj)
{
try
{
// I'll get here in simulation/debug build but not in release build on device
await Application.Current.MainPage.DisplayAlert("Go", "Go", "Ok");
await _navigation.PushAsync(new TestView(), false);
}
catch (Exception exc)
{
await Application.Current.MainPage.DisplayAlert("Error", exc.Message, "Cancel");
}
}
我的整个应用程序在模拟器上运行得很好。如果我在我真正的物理设备上按下按钮,我会看到视觉反馈(按钮改变颜色),但什么也没发生。
到目前为止,我尝试的是:
-
应用了一些printf调试
DisplayAlert
-
将蓝牙鼠标连接到我的android设备(android 6.0),以防鼠标点击和手指点击之间存在差异(仍然没有工作按钮)
更新
我通过USB连接android手机进行调试。该按钮在调试模式下工作(正在命中断点,打开新页面),但在发布版本中仍然不起作用。