【发布时间】:2021-01-07 20:43:13
【问题描述】:
我正在使用 Xamarin Forms 开发移动应用程序。我想在应用程序中按下按钮时显示某些文本,否则隐藏。但是,我不确定如何使用 XAML 和 C# 来执行此操作。我尝试使用 Console.WriteLine() 命令编写条件,但文本未显示在应用程序中。有没有关于如何解决这个问题的建议,或者我应该查看哪些资源来了解更多信息?
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# 代码:
/* 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!";
}
【问题讨论】:
-
使用任何 UI 元素的
IsVisible属性来显示/隐藏它。如果您需要进一步的帮助,请发布相关代码,以便我们了解您在做什么。 -
嗨!现在添加代码。感谢您的建议和回答。
-
我仍然不知道你想做什么。有两个按钮——当用户点击它们时会发生什么?您希望在单击另一个按钮时隐藏一个按钮吗?
-
嗨!单击一个按钮时,我希望文本出现在按钮下方(一个按钮的某些文本,另一个按钮的不同文本)。我希望这能消除您的困惑。
标签: c# android ios xaml xamarin.forms