【问题标题】:Shell BackButtonBehavior command binding not working in UWPShell BackButtonBehavior 命令绑定在 UWP 中不起作用
【发布时间】:2021-03-07 17:00:29
【问题描述】:

我对 Xamarin 开发有点陌生。我尝试使用绑定命令更改后退按钮的行为,但这似乎不起作用。这是视图的代码:

<Shell.BackButtonBehavior>
    <BackButtonBehavior Command="{Binding GoBack}"/>
</Shell.BackButtonBehavior>

这是视图模型的代码:

public CreatePasswordVM()
{
    _goBack = new Command(GoBackButton);
}
private ICommand _goBack;
public ICommand GoBack
{
    get { return _goBack; }
}
public async void GoBackButton()
{
    await Shell.Current.GoToAsync("../..");
}

当我按下后退按钮时,“GoBackButton”方法没有调用。我想提一下 Android 上的作品。

【问题讨论】:

  • 缺少绑定上下文?检查this discussionSample in the docs 没有使用 mvvm 顺便说一句。
  • 不,BindingContext 没有丢失……是不是我用mvvm有问题?
  • @himynameisgarch,我可以重现您的问题,原因是 uwp 平台尚未实现 BackButtonBehavior。我已经把源代码贴在下面了,请看一下。
  • @NicoZhu-MSFT 我看到了,我已经在 Xamarin Forms github 上提出了问题!谢谢!

标签: xamarin xamarin.forms uwp xamarin.uwp xamarin.shell


【解决方案1】:

Shell BackButtonBehavior 命令绑定在 UWP 中不起作用

源自 Xamarin Form 源代码。 BackButtonBehavior还没有针对UWP平台实现,我们可以找到Android和IOS实现herehere。但是对于 uwp 没有这样的跟踪器,并且在 UWP ShellRenderer 中没有这样的值。对于这种情况,我们建议您在Xamarin Forms github 中发布新功能请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    • 2018-03-15
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多