2016-06-21 82 views

回答

1

您不能使用默认的Xamarin警报。

看看ACR.UserDialogs NuGet包。它确实支持CancellationToken s。或者如果您感觉勇敢的挖掘GitHub上的Xamarin.Forms回购并自己创建一个拉取请求!

0

我已创建自定义displayalert您可以使用任务回拨TaskCompletionSource如xamarin在我的方法建立DisplayAlert from it

public async Task<bool> ShowDialogAsync(string title, string message, string acceptMessage, string cancelMessage) 
       { 
        Grid ShowDialogMessage = null; 
        Grid CurrentPageGrid = (App.Instance.CurrentPage as ContentPage).Content as Grid; 
        TaskCompletionSource<bool> result = new TaskCompletionSource<bool>(); 
        try 
        { 
         ShowDialogMessage = GenericView.CustomDisplayAlert(message, CurrentPageGrid.RowDefinitions.Count, CurrentPageGrid.ColumnDefinitions.Count,() => 
         { 
     //here you can add your implementation 
          CurrentPageGrid.Children.Remove(ShowDialogMessage); 

    result.SetResult(true); 

         }, 
         () => 
         { 
     //here you can add your implementation  
          CurrentPageGrid.Children.Remove(ShowDialogMessage); 
          result.SetResult(false); 
         }, title, acceptMessage, cancelMessage); 

         CurrentPageGrid.Children.Add(ShowDialogMessage); 
         return await result.Task; 
        } 
        catch (Exception ex) 
        { 
         return await App.Current.MainPage.DisplayAlert(title, message, acceptMessage, cancelMessage); 
     #if DEBUG 
         throw ex; 
     #endif 
        } 

       } 

我加入行动落实回调,,方法签名

public static Grid CustomDisplayAlert(string message, int rows, int columns, Action acceptAction, Action cancelAction, string title = "", string acceptMessage = "", string cancelMessage = "") 
     { .....