我正在使用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!";
}
答案 0 :(得分:0)
您需要使用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" />
然后在后面的代码中可以更改每个标签的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;
}