如何用Xamarin的随机列表更改标签
我是Xamarin的新手,我想制作一个应用程序,每天都会更改短语。我想使用计时器更改短语。
我尝试了几个教程,但对我不起作用。
这是我XAML和C#代码上的一个示例:
xaml
<ScrollView Grid.Row="1">
<StackLayout Orientation="Vertical" Padding="30,24,30,24" Spacing="10">
<Label x:Name="Label_Time" Text="[TIME]" FontSize="Title" HorizontalOptions="Center"/>
<Label Text="before the new enigma" FontSize="Subtitle" HorizontalOptions="Center"/>
<Label Text="You can resolve now or waiting tomorrow for a new enigma." FontSize="20" Padding="0,0,0,0"/>
<Entry x:Name="Label_Answer" Placeholder="Enter the answer"/>
<Button Text="Answer" BackgroundColor="#487eb0" Clicked="OnButtonClicked"/>
</StackLayout>
</ScrollView>
c#
public void RandomEnigma(object sender, EventArgs e)
{
var enigmas = new List<string>()
{
"My first is the main color of the earth, my second can be used to move, my third is for surviving. My everything is a liquid. What is that ?",
"Very childish, I can introduce children to programming. What is my name ?",
};
}
private void OnButtonClicked(object sender, EventArgs e)
{
// WIP
}
I'm new to Xamarin, I want to make an application who every day, a phrase change. I want to use a timer to change the phrase.
I tried several tutorials but didn't work to me.
Here's a example on my XAML and C# code who I made actualy:
XAML
<ScrollView Grid.Row="1">
<StackLayout Orientation="Vertical" Padding="30,24,30,24" Spacing="10">
<Label x:Name="Label_Time" Text="[TIME]" FontSize="Title" HorizontalOptions="Center"/>
<Label Text="before the new enigma" FontSize="Subtitle" HorizontalOptions="Center"/>
<Label Text="You can resolve now or waiting tomorrow for a new enigma." FontSize="20" Padding="0,0,0,0"/>
<Entry x:Name="Label_Answer" Placeholder="Enter the answer"/>
<Button Text="Answer" BackgroundColor="#487eb0" Clicked="OnButtonClicked"/>
</StackLayout>
</ScrollView>
C#
public void RandomEnigma(object sender, EventArgs e)
{
var enigmas = new List<string>()
{
"My first is the main color of the earth, my second can be used to move, my third is for surviving. My everything is a liquid. What is that ?",
"Very childish, I can introduce children to programming. What is my name ?",
};
}
private void OnButtonClicked(object sender, EventArgs e)
{
// WIP
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在每次使用以下代码的情况下每次生成0和数组范围的数字:
此后,将Arry的值分配给标签:
You can generate a number between 0 and the range of array
enigmas
each time with the following code:And after that, assign a value of the arry to a label: