Change Label.Text using DisplayPromptAsync(): 使用DisplayPromptAsync()更改Label.Text。

huangapple go评论106阅读模式
英文:

MAUI: Change Label.Text using DisplayPromptAsync()

问题

<Label Grid.Row="2" Text="UserName" x:Name="LabelName" FontAttributes="Bold" TextColor="White" HorizontalTextAlignment="Center" Margin="0,-45,0,0" FontSize="22"/>

<Button Grid.Column="1"  WidthRequest="115" HeightRequest="45" Text="Name" TextColor="White" Margin="200, 2 ,200, -274"  CornerRadius="19" Clicked="NameClicked"/>
private async void NameClicked(object sender, EventArgs e)
{
    var ResultName = await DisplayPromptAsync("Insira seu Nome", "Favor inserir seu Nome","Ok");

    LabelName.Text = ResultName;
}
英文:

I want to change the Content of a Label through the Pop-pup DisplayPromptAsync() which allows you to type text and save the text to use, but when I try to apply it does not work.

Label in XAML:

<Label Grid.Row="2" Text="UserName" x:Name="LabelName" FontAttributes="Bold" TextColor="White" HorizontalTextAlignment="Center" Margin="0,-45,0,0" FontSize="22"/>

Button in XAML:

<Button Grid.Column="1"  WidthRequest="115" HeightRequest="45" Text="Name" TextColor="White" Margin="200, 2 ,200, -274"  CornerRadius="19" Clicked="NameClicked"/>

Code-behind of Button:

private async void NameClicked(object sender, EventArgs e)
{
    var ResultName = await DisplayPromptAsync("Insira seu Nome", "Favor inserir seu Nome","Ok");

    LabelName.Text = ResultName;
}

I hoped that as soon as he kept the text in the variable could already assign and change quietly, only the code has no error is not working.

答案1

得分: 0

<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">

&lt;Label Text="用户名" x:Name="LabelName" FontSize="22"/&gt;

&lt;Button Clicked="NameClicked"/&gt;

</VerticalStackLayout>

这是.xaml文件中的代码。

private async void NameClicked(object sender, EventArgs e)
{
var ResultName = await DisplayPromptAsync("请输入您的姓名", "请输入您的姓名", "确定");

LabelName.Text = ResultName.ToString();

}

这是.cs文件中的代码。

英文:

I create a demo and here is the code in .xaml. It works well on my side.

&lt;VerticalStackLayout
            Spacing=&quot;25&quot;
            Padding=&quot;30,0&quot;
            VerticalOptions=&quot;Center&quot;&gt;
            
            &lt;Label Text=&quot;UserName&quot;  x:Name=&quot;LabelName&quot; FontSize=&quot;22&quot;/&gt;

            &lt;Button Clicked=&quot;NameClicked&quot;/&gt;

 &lt;/VerticalStackLayout&gt;

Here is the code in .cs file.

private async void NameClicked(object sender, EventArgs e)
    {
        var ResultName = await DisplayPromptAsync(&quot;Insira seu Nome&quot;, &quot;Favor inserir seu Nome&quot;, &quot;Ok&quot;);

        LabelName.Text = ResultName.ToString();
    }

huangapple
  • 本文由 发表于 2023年1月6日 13:34:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定