英文:
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">
<Label Text="用户名" x:Name="LabelName" FontSize="22"/>
<Button Clicked="NameClicked"/>
</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.
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Label Text="UserName" x:Name="LabelName" FontSize="22"/>
<Button Clicked="NameClicked"/>
</VerticalStackLayout>
Here is the code in .cs file.
private async void NameClicked(object sender, EventArgs e)
{
var ResultName = await DisplayPromptAsync("Insira seu Nome", "Favor inserir seu Nome", "Ok");
LabelName.Text = ResultName.ToString();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论