【问题标题】:Redirect to another page from DisplayAlert Popup Xamarin.Form从 DisplayAlert Popup Xamarin.Form 重定向到另一个页面
【发布时间】:2016-12-31 07:35:42
【问题描述】:

大家好,我正在使用 Autofac(MVVM) 我的问题是如何通过单击弹出屏幕中的确定按钮从 DisplayAlert Popup 重定向到另一个页面?由于显示警报在我的视图和视图模型中,因此导航到另一个页面的 ICommand 是导航器。

         PushAsync<PageViewModel>();

我的一些代码片段:

视图模型

   public class HomePageViewModel : ViewModelBase
   {
    private readonly INavigator _navigator;

    public HomePageViewModel(INavigator navigator)
    {
        _navigator = navigator;
        CmdInvites = new Command(Cmdinvites);
    }

    public ICommand CmdInvites { get; private set; }


    //Invite PhoneBook
    private void Cmdinvites()
    {
        _navigator.PushAsync<PhoneContactViewModel>();
    }

  }


 zxing.OnScanResult += (result) =>
 Device.BeginInvokeOnMainThread(async () => {
 // Stop analysis until we navigate away so we don't keep reading barcodes
     zxing.IsAnalyzing = false;
     // Show an alert
     await DisplayAlert("Scanned Barcode", result.Text, "OK");
     // Navigate away
     await Navigation.PopAsync();
      <-------------this is where i want to redirect the {Binding CmdInvites}           
 });

感谢您花时间阅读我的帖子。

【问题讨论】:

  • 只需推送到导航堆栈。有什么问题?
  • 您是否要离开扫描页面?扫描完成后。
  • @AnubhavRanjan 正是我想要做的,扫描后导航到另一个页面。
  • @jaketalledo 你可以在 Github 上上传你的代码吗?

标签: mvvm xamarin xamarin.forms xamarin-studio


【解决方案1】:

您可以使用另一个 DisplayAlert 方法构造函数,如下所示:

Device.BeginInvokeOnMainThread(async () => {
 // Stop analysis until we navigate away so we don't keep reading barcodes
     zxing.IsAnalyzing = false;
     // Show an alert
     if(await DisplayAlert("Scanned Barcode", result.Text, "Accept","Cancel"))
     {
     // Navigate away
     await Navigation.PopAsync();
      <-------------this is where i want to redirect the {Binding CmdInvites}
     }      
 });

【讨论】:

  • 当我调试我的错误是无法解析类型 _inavigator.pushasync();我已经注册到 containerbuilder
  • 那是另外一回事,它基本上指出发生这种情况是因为没有注册一些东西。看看你缺少什么,例如 IViewModel、INavigationServce 等。
猜你喜欢
  • 2016-12-14
  • 1970-01-01
  • 2015-08-14
  • 1970-01-01
  • 2020-01-30
  • 2018-12-26
  • 1970-01-01
  • 2014-02-17
  • 1970-01-01
相关资源
最近更新 更多