简体   繁体   English

隐藏/显示 Xamarin Forms 中的文本

[英]Hiding/Showing text in Xamarin Forms

I am working to develop a mobile application using Xamarin Forms. I would like to make certain text appear when a button is pushed in the application, and otherwise be hidden.我正在使用 Xamarin Forms 开发移动应用程序。我想在应用程序中按下按钮时显示某些文本,否则隐藏。 However, I am not sure how to do this using XAML and C#. I tried writing a conditional, with a Console.WriteLine() command, but the text does not show in the application.但是,我不确定如何使用 XAML 和 C# 执行此操作。我尝试使用 Console.WriteLine() 命令编写条件,但文本未显示在应用程序中。 Are there any suggestions on how to solve this problem, or what resources I should look into to learn more about this?是否有关于如何解决此问题的任何建议,或者我应该查看哪些资源以了解更多信息?

XAML Code - Buttons: XAML 代码 - 按钮:

 <Button Text="I am new to this app" Clicked="Button_Clicked"> 
 </Button><Button Text="I have used this app before" Clicked="Button_Clicked_1"></Button

C# Code for these buttons: C# 这些按钮的代码:

    /* This only changes the label of the buttons, it doesn't make the text appear separately like I want it to.*/

  void Button_Clicked (System.Object sender, System.EventArgs e)
    {
        ((Button)sender).Text = "Hey there! Welcome to this awesome app!";

    }

    void Button_Clicked_1(System.Object sender, System.EventArgs e)
    {
        ((Button)sender).Text = "Welcome back!";

    }

You need to use Labels to display the additional text您需要使用Labels来显示附加文本

<Button x:Name="Button1" Text="I am new to this app" Clicked="Button_Clicked" /> 
<Label x:Name="Label1" Text="Hey there! Welcome to this awesome app!" IsVisible="False" />
<Button x:Name="Button2" Text="I have used this app before" Clicked="Button_Clicked_1" />
<Label x:Name="Label2" Text="Welcome back!" IsVisible="False" />

then in the code behind you can change the IsVisible property of each label然后在后面的代码中,您可以更改每个 label 的IsVisible属性

void Button_Clicked (System.Object sender, System.EventArgs e)
{
    Label1.IsVisible = true;
}

void Button_Clicked_1(System.Object sender, System.EventArgs e)
{
    Label2.IsVisible = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM