Home › Forums › Software Development › [WPF] UserControl GazeAwareness odd problem
- This topic has 6 replies, 3 voices, and was last updated 7 years, 4 months ago by
Grant [Tobii].
- AuthorPosts
- 23/02/2016 at 17:04 #4527
Florent
ParticipantHi,
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.
24/02/2016 at 14:48 #4536Florent
ParticipantHere is .zip of my project, it should be easier to launch :
04/04/2016 at 15:57 #4955Eddie [Tobii]
ParticipantHi 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,
Eddie08/08/2016 at 16:59 #5506Florent
ParticipantHi there,
Is the solution released in the actual version of your SDK (1.7.480) ? Because i still have the same problem …
Regards,
Florent09/08/2016 at 12:32 #5513Grant [Tobii]
KeymasterHi @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?
09/08/2016 at 14:39 #5515Florent
ParticipantYup, 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
11/08/2016 at 13:29 #5530Grant [Tobii]
KeymasterHi @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.
- AuthorPosts
- You must be logged in to reply to this topic.