代码之家  ›  专栏  ›  技术社区  ›  nabulke

在发布版本中未触发命令

  •  1
  • nabulke  · 技术社区  · 7 年前

    按钮从我的视图绑定到我的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手机进行调试。该按钮在调试模式下工作(正在命中断点,打开新页面),但在发布版本中仍然不起作用。

    enter image description here enter image description here

    1 回复  |  直到 7 年前
        1
  •  2
  •   nmilcoff    7 年前

    如果在中将链接选项设置为“仅SDK程序集”,则发布版本将起作用 Build

    当 linker 如果启用并设置为“SDK和用户程序集”,则会删除大量代码(按此键不使用)。在你的情况下 NewErrorCommand 属性正在剥离,因为该工具假定您没有使用它。

    如果将其设置为“仅SDK程序集”,则该选项有效,因为在该配置下,链接器不会接触任何您自己的程序集。

    推荐文章