Home Forums Software Development Use fixation to 'select' an element in WPF Reply To: Use fixation to 'select' an element in WPF

#7614
Miles Bardon
Participant

Hi Grant,

Thanks so much for that code, it really helped.
I have made adjustments to the WinForms GazeAwareForm to suit my purpose. Essentially I have set up a 2s timer which activates or deactivates based on whether an element has the gaze for that period.

private void OnGaze(object sender, GazeAwareEventArgs e)
        {
            var panel = sender as Panel;
            if (panel != null)
            {
                if (e.HasGaze)
                {
                    panel.BorderStyle = BorderStyle.FixedSingle;
                    timer.Enabled = true;
                }
                else
                {
                    panel.BorderStyle = BorderStyle.None;
                    timer.Enabled = false;
                }
            }
        }

And to demonstrate I update a counter on the form.

private void OnTimedEvent(object source, ElapsedEventArgs e)
 {
       UpdateCounter();
 }

private void UpdateCounter()
{
    if (clickCount.InvokeRequired)
        clickCount.Invoke((MethodInvoker)delegate { clickCount.Value++; });
    else
        clickCount.Value++;
}

This makes it possible to ‘click’ on an object completely hands-free.
What do you think of this implementation? It works in practice but is there perhaps a more elegant way you know?

Many thanks again