3
votes

I refer Xamarin.Forms docs. the link add below enter link description here Please anyone has a solution Please help me * DisplayPrompt implementation

XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         x:Class="tEST.MainPage">

    <StackLayout Margin="20,35,20,20">
    <Label Text="Display Prompt"
           FontSize="Large"
           HorizontalOptions="Center" />
    <Button Text="Question 1"
            Clicked="OnQuestion1ButtonClicked" />
    <Label x:Name="question1ResultLabel" />
    <Button Text="Question 2"
            Clicked="OnQuestion2ButtonClicked" />
    <Label x:Name="question2ResultLabel" />
</StackLayout>

</ContentPage>

C#

using System;
using Xamarin.Forms;

namespace tEST
{
public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    async void OnQuestion1ButtonClicked(object sender, EventArgs e)
    {
        string result = await DisplayPromptAsync("Question 1", "What's your name?");
        if (!string.IsNullOrWhiteSpace(result))
        {
            question1ResultLabel.Text = $"Hello {result}.";
        }
    }

    async void OnQuestion2ButtonClicked(object sender, EventArgs e)
    {
        string result = await DisplayPromptAsync("Question 2", "What's 5 + 5?", maxLength: 2, keyboard: Keyboard.Numeric);
        if (!string.IsNullOrWhiteSpace(result))
        {
            int number = Convert.ToInt32(result);
            question2ResultLabel.Text = number == 10 ? "Correct." : "Incorrect.";
        }
    }
}
}

Getting errors:

1.CS0103 The name 'DisplayPromptAsync' does not exist in the current context

2.Severity Code Description Project File Line Suppression State Suppression State Error The "FilterAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not find file 'C:\Users\Sharjas K M\source\repos\tEST\tEST\tEST\bin\Debug\netstandard2.0\tEST.dll'. File name: 'C:\Users\Sharjas K M\source\repos\tEST\tEST\tEST\bin\Debug\netstandard2.0\tEST.dll' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Xamarin.Android.Tasks.FilterAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

3

3 Answers

4
votes

Note: DisplayPromptAsync is feature of Xamarin.Forms 4.3.0

If you want to show alert

bool result= await DisplayAlert ("Alert", "Continue..", "Yes", "No");

If you want to take input from user

string result = await DisplayPromptAsync("Question 1", "What's your name?");

Where result you return you value entered by user.

3
votes

DisplayPrompt is available after XF 4.3 . So you could firstly update the version of Xamarin.Forms in Nuget . Then delete the folder bin and obj in your share project. Then clean and rebuild it.

enter image description here

Note: The DisplayPromptAsync method is currently only implemented on iOS and Android(So in UWP you could not call it).

1
votes

The mistake I made Xamarin.Forms not updated. DisplayPromptAsync is a recent addition. You may need to update the Xamarin.Forms version 4.3.0.991221 NuGet package.DisplayPromptAsync is not yet implemented on UWP.