using System; using System.Reflection; using SampleApp.DependencyServices; using Xamarin.Forms; namespace SampleApp.Views { public partial class Functionality5 : ContentPage { //label Label label= new Label { Text = "Does the Bell's Image Have the Focus?", HorizontalOptions = LayoutOptions.CenterAndExpand }; Label labelYN = new Label { Text = "YES/ NO", HorizontalOptions = LayoutOptions.CenterAndExpand }; Label infoLabel = new Label { Text = "i: This view updates every 2 seconds", HorizontalOptions = LayoutOptions.CenterAndExpand, Margin = new Thickness(0, 200) }; IIsFocused dependency; bool onView = true; public Functionality5() { InitializeComponent(); dependency = DependencyService.Get(); background.Children.Add(label); background.Children.Add(labelYN); background.Children.Add(infoLabel); AutomationProperties.SetIsInAccessibleTree(label, true); AutomationProperties.SetIsInAccessibleTree(labelYN, true); AutomationProperties.SetIsInAccessibleTree(infoLabel, true); AutomationProperties.SetIsInAccessibleTree(bellImage, true); AutomationProperties.SetHelpText(bellImage, "Bell Image"); // timer che si ripete ogni 2 secondi Device.StartTimer(TimeSpan.FromSeconds(2.0), () => { if (onView) { Console.WriteLine("TIMER FIRED"); Device.BeginInvokeOnMainThread(() => { if (dependency.isFocused(bellImage)) { Console.WriteLine("is focused"); labelYN.TextColor = Color.Green; labelYN.Text = "YES"; } else { Console.WriteLine("is NOT focused"); labelYN.TextColor = Color.Red; labelYN.Text = "NO"; } }); return true; // timer runs again } return false; //timer stops }); } //stop the timer when view changes protected override void OnDisappearing() { base.OnDisappearing(); onView = false; } } }