简体   繁体   English

背景色定时器 Xamarin forms

[英]Background colour timer Xamarin forms

I want to involve a feature in a Xamarin Forms app.我想在 Xamarin Forms 应用程序中加入一个功能。 This feature should allow a colour to be displayed until the user clicks the screen/ a button, and records the time taken to do so (almost like a reaction time thing.) This should repeat for different colours, with a pause between each of a white screen.此功能应允许在用户单击屏幕/按钮之前显示颜色,并记录这样做所花费的时间(几乎就像反应时间一样。)这应该针对不同的颜色重复,每个 a 之间有一个暂停白屏。

I currently have the main page in MainPage.Xaml, which gives the user the option to click Play Game, taking them to PlayGame.Xaml and PlayGame.Xaml.Cs我目前在 MainPage.Xaml 中有主页,用户可以选择单击 Play Game,将他们带到 PlayGame.Xaml 和 PlayGame.XamlC。

在此处输入图像描述

I have experience using C sharp, but have never wrote in Xaml before.我有使用 C 的经验,但之前从未在 Xaml 中写过。 I am mainly struggling with getting a instructions from the PlayGame.Xaml.Cs to PlayGame.Xaml, ie random background colour, and a timer.我主要是在努力从 PlayGame.Xaml.Cs 到 PlayGame.Xaml 获得指令,即随机背景颜色和计时器。

What I mean to say is that while I can separately create a screen with a background colour and a button in the xaml page, and also create a random timer in the c sharp page, I don't know how to combine the 2. Any help?我的意思是,虽然我可以在xaml页面中单独创建一个带有背景颜色和一个按钮的屏幕,并且还可以在c锐利页面中创建一个随机计时器,但我不知道如何组合2。任何帮助?

Sorry for poor english, feel free to comment any questions for clarity.抱歉英语不好,请随时评论任何问题以清楚起见。

in the code behind (xaml.cs) of a page, you can access the page's properties directly在页面背后的代码 (xaml.cs) 中,您可以直接访问页面的属性

BackgroundColor = Color.Yellow;

or you can address individual XAML element by using their name property或者您可以使用其名称属性来处理单个 XAML 元素

<Label x:Name="myLabel" ... />

then in the code然后在代码中

myLabel.BackgroundColor = Color.Blue;

this applies to any property, not just BackgroundColor这适用于任何属性,而不仅仅是BackgroundColor

you can also use databinding to control XAML properties from you model您还可以使用数据绑定来控制 model 的 XAML 属性

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

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