Functionality3.xaml.cs 1.25 KB
Newer Older
Mattia's avatar
Mattia committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
using System;
using System.Collections.Generic;

using Xamarin.Forms;
using SampleApp.DependencyServices;

namespace SampleApp.Views
{
    public partial class Functionality3 : ContentPage
    {
        IAssignFocus assignFocus;
        IScreenReaderEnabled screenReaderEnabled;
        Boolean focus = true;
        public Functionality3()
        {
            InitializeComponent();
            assignFocus = DependencyService.Get<IAssignFocus>();
            screenReaderEnabled = DependencyService.Resolve<IScreenReaderEnabled>();
            AutomationProperties.SetIsInAccessibleTree(label, true);
        }

        void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            if (screenReaderEnabled.IsScreenReaderEnabled())
            {
                if (focus)
                {
                    assignFocus.AssignFocus(label);
                    label.Text = "I Have Focus";
                    button.Text = "Reset";
                }
                else
                {
                    assignFocus.AssignFocus(button);
                    label.Text = "I Don't Have Focus";
                    button.Text = "Assign focus to the label above";
                }
                focus = !focus;
            }

        }
    }
}