gpt4 book ai didi

xamarin - 我无法在我的示例项目中实现 DisplayPrompt

转载 作者:行者123 更新时间:2023-12-04 00:02:06 26 4
gpt4 key购买 nike

我引用 Xamarin.Forms 文档。链接添加在下面 enter link description here请任何人有解决方案请帮助我* DisplayPrompt 实现

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.";
}
}
}
}

出现错误:

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()

最佳答案

注意:DisplayPromptAsync 是 Xamarin.Forms 4.3.0 的功能

如果你想显示alert

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

如果你想从用户那里获取输入

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

result 你返回用户输入的值。

关于xamarin - 我无法在我的示例项目中实现 DisplayPrompt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59172631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com