Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to await a DisplayAlert from a page (without async-Button-event)..?

$
0
0

Hi all

This problem follows me, since I work with XF... :-)

On my search-page, I have various search-options (ListViews, SearchBars, etc.).
If the user has searched already and then search once again, I want to ask him, if he want to reset the search-options or not (I have to know this before the page-content is created).
Therefore, I want to display a simple DisplayAlert from the page-definition-code (where the content of the page is defined).
Example:

var AnswerYes = await DisplayAlert("Question","Do you want to reset the search-options?", "Yes", "No");
if (AnswerYes)
 {
  // Reset the search-options
 }
 else
  {
     // Do nothing
  }

The problem is simply, that I have to await the DisplayAlert and the page-definition-code is not async.
If I put the DisplayAlert in a async-function (Task) and call the function without await (the async-function then returns true or false), I got the error-message "A implicit convert from type 'System.Threading.Tasks.Task' in 'bool' is not possible.

So... how to solve this nasty problem?

Or.. is this simply not possible and the only way is, to show the DisplayAlert before the search-page is created?

Thanks for any answer...


Viewing all articles
Browse latest Browse all 58056

Trending Articles