Home Forums Software Development [WPF] UserControl GazeAwareness odd problem

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #4527
    Florent
    Participant

    Hi,

    I would like to display gaze aware UserControls on a MainWindow depending on which button is clicked.

    In order to do so, I have created a WPF program which display these UserControls on a grid called DisplayGrid. They are children of this grid depending of which button is activated. All Buttons are written ‘gaze aware’ in XAML code, which are MainWindow’s Buttons(MainButtons) and UserControls’ buttons.

    There is my problem and not a simple one : on the first MainButton activation, UserControl displayed is not gaze aware. Button on this UserControl don’t react to my gaze.
    Then I click on second MainButton, which display the second UserControl with its button, but this one is gaze aware.
    The next MainButton activations will result as the first problem, UserControls buttons will be not gaze aware.

    I don’t know from where the source problem is …
    I have tried a lot of things, and i only have solution which is to recreate UserControls objets (VehicleControlsUC and VentilationControlsUC) just before apply function changeUC(param). This is not what i planned to do …

    Maybe you could help me ?

    MainWindow.xaml

    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:eyeX="clr-namespace:EyeXFramework.Wpf;assembly=EyeXFramework"
    
            x:Class="blank_eye_tracking.MainWindow"
            Title="MainWindow"
            WindowStyle="None"
            ResizeMode="NoResize"  
            WindowState="Maximized"
            TextOptions.TextFormattingMode="Display"
            TextOptions.TextRenderingMode="Auto">
    
        <Window.Resources>
            <Style x:Key="EyeXGazeAwareElement"
                   TargetType="FrameworkElement">
                <Setter Property="eyeX:Behavior.GazeAware" Value="True"/>
                <Setter Property="eyeX:Behavior.GazeAwareDelay" Value="0"/>
            </Style>
    
            <Style x:Key="MainButtonStyle"
                   TargetType="Button"
                   BasedOn="{StaticResource EyeXGazeAwareElement}">
                <Setter Property="Button.Background" Value="BlueViolet"/>
                <Style.Triggers>
                    <Trigger Property="eyeX:Behavior.HasGaze" Value="True">
                        <Setter Property="Button.Background" Value="WhiteSmoke"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Window.Resources>
    
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="8*"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid Name="DisplayGrid"
                  Grid.Column="0"
                  Visibility="Visible">
            </Grid>
            <StackPanel Orientation="Vertical"
                        Grid.Column="1">
                <!-- These buttons are gaze aware on any time, no problem here -->
                <Button Name="Main_Button1"
                        Click="Main_Button1_Click"
                        Height="250"
                        Style="{StaticResource MainButtonStyle}"/>
                <Button Name="Main_Button2"
                        Click="Main_Button2_Click"
                        Height="250"
                        Style="{StaticResource MainButtonStyle}"/>
            </StackPanel>
        </Grid>
    </Window>

    MainWindow.xaml.cs

    namespace blank_eye_tracking
    {
        using System.Windows;
        using System.Windows.Controls;
        using System.Windows.Input;
        using System.Windows.Media.Animation;
        using System.Threading.Tasks;
        using System.Threading;
        using System;
        using System.Collections.Generic;
        using System.Windows.Media;
    
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            // ActualPage is DisplayGrid's actual child
            UserControl ActualPage;
    
            // Instanciate the UserControls as MainWindow's attributes (to use them on any time)
            VentilationControls VentilationUC = new VentilationControls();
            VehicleControls VehicleControlsUC = new VehicleControls();
    
            public MainWindow()
            {
                InitializeComponent();
    
                this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
            }
    
            private void HandleEsc(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Escape)
                {
                    this.Close();
                }
            }
    
            private void Main_Button1_Click(object sender, RoutedEventArgs e)
            {
                //VentilationControls VentilationUC = new VentilationControls();
                changeUC(VentilationUC);
            }
    
            private void Main_Button2_Click(object sender, RoutedEventArgs e)
            {
                //VehicleControls VehicleControlsUC = new VehicleControls();
                changeUC(VehicleControlsUC);
            }
    
            private void changeUC(UserControl UCPage)
            {
                // Initial time when no UserControl is displayed
                if (ActualPage == null)
                {
                    DisplayGrid.Children.Add(UCPage);
                    ActualPage = (UserControl)VisualTreeHelper.GetChild(DisplayGrid, 0);    // Add new UC as ActualPage
                }
                // Check if actual UserControl displayed is a different one 
                else if (!(ActualPage.Equals(UCPage)))
                {
                    DisplayGrid.Children.Clear();                                           // Clear all DisplayGrid children
                    DisplayGrid.Children.Add(UCPage);                                       // Add UserControl parameter as a child of DisplayGrid
                    ActualPage = (UserControl)VisualTreeHelper.GetChild(DisplayGrid, 0);    // Refresh ActualPage to be used on "if-else if"
                }
            }
        }
    }

    VentilationControls.xaml

    <UserControl x:Class="blank_eye_tracking.VentilationControls"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:eyeX="clr-namespace:EyeXFramework.Wpf;assembly=EyeXFramework"
                 mc:Ignorable="d">
        
        <UserControl.Resources>
            <Style x:Key="testbutton2"
                   TargetType="Button">
                <Setter Property="Button.Background" Value="Pink"/>
                <Setter Property="eyeX:Behavior.GazeAware" Value="True"/>
                <Setter Property="eyeX:Behavior.GazeAwareDelay" Value="0"/>
                <Style.Triggers>
                    <Trigger Property="eyeX:Behavior.HasGaze" Value="True">
                        <Setter Property="Button.Background" Value="Teal"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </UserControl.Resources>
        
        <Grid Margin="100 0 0 0">
            <Button Style="{StaticResource testbutton2}"
                    Height="300"
                    Width="300"/>
        </Grid>
    </UserControl>

    VehicleControls.xaml

    <UserControl x:Class="blank_eye_tracking.VehicleControls"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:eyeX="clr-namespace:EyeXFramework.Wpf;assembly=EyeXFramework"
                 mc:Ignorable="d">
        
        <UserControl.Resources>
            <Style x:Key="testbutton1"
                   TargetType="Button">
                <Setter Property="Button.Background" Value="Red"/>
                <Setter Property="eyeX:Behavior.GazeAware" Value="True"/>
                <Style.Triggers>
                    <Trigger Property="eyeX:Behavior.HasGaze" Value="True">
                        <Setter Property="Button.Background" Value="Green"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </UserControl.Resources>
    
        <Grid Margin="0 0 100 0">
            <Button Style="{StaticResource testbutton1}"
                    Height="300"
                    Width="300"/>
        </Grid>
    </UserControl>

    VehicleControls.xaml.cs and VentilationControls.xaml.cs have the basic code inside.

    #4536
    Florent
    Participant
    #4955
    Eddie [Tobii]
    Participant

    Hi Florent,

    Thank you for attaching your project to help us find the problem. I have traced down a bug in the SDK which deletes the interactor for a FrameworkElement when the element is unloaded and loaded again. We have a solution for it and it will be included in the next release of the SDK.

    The only workaround I have found is what you have already mentioned, to recreate the UserControl object each time you want to show it.

    Best regards,
    Eddie

    #5506
    Florent
    Participant

    Hi there,

    Is the solution released in the actual version of your SDK (1.7.480) ? Because i still have the same problem …

    Regards,
    Florent

    #5513
    Grant [Tobii]
    Keymaster

    Hi @florentd, there have a been a significant number of updates to the EyeX SDK since April.

    Have you got the latest and still the issue is ongoing?

    #5515
    Florent
    Participant

    Yup, i have downloaded and added your current version of Tobii SDK on my project and the issue is still ongoing … Version is the 1.7.480

    #5530
    Grant [Tobii]
    Keymaster

    Hi @florentd, okay I did some digging around for your particular issue and the work is still ongoing.

    We do however hope to have another updated version of the EyeX SDK coming soon within the next few weeks.

    Apologies for the inconvenience, be sure to check our downloads section for updates.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.