[Back to the SDK start page]
C# WPF Sample Walkthrough
This section describes the typical workflow when using the C# WPF Binding API of the Interaction Library SDK.
In our WPF application XAML code, we tell the Interaction Library about the 3 rectangles in our WPF window (A, B and C in the picture below) and request that they are gaze aware, using the WPF dependency property IsGazeAware
. Such a region is called an interactor in the Interaction Library API.
As the user's gaze enters and leaves the interactors, the WPF dependency property HazGaze
changes, so that we can react to it in our WPF application XAML code.
The above dependency properties exists in the Tobii.InteractionLib.Wpf.Behaviors class.
A WPF window with 3 vertical interactors A, B and C:
+-----------------------------------+
| |
| +-------+ +-------+ +-------+ |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | A | | B | | C | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| +-------+ +-------+ +-------+ |
| |
+-----------------------------------+
The Interaction Library WPF host instance is kept until the application exits - the window accesses it during construction:
namespace Tobii.InteractionLib.Wpf.SampleApp
{
public partial class App : Application
{
We create the host when the application starts up:
The host is disposed to release any remaining resources held by it when the application exits:
protected override void OnExit(ExitEventArgs e)
{
IntlibWpf?.Dispose();
base.OnExit(e);
}
}
}
When the main application window is constructed, it adds itself to the host:
public MainWindow()
{
((App)Application.Current).IntlibWpf?.WpfBinding?.AddWindow(this);
InitializeComponent();
}
The window XAML gets access to the dependency properties IsGazeAware
and HasGaze
by referring to the Tobii.InteractionLib.Wpf namespace in the assembly with the same name:
<Window x:Class="Tobii.InteractionLib.Wpf.SampleApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wpf="clr-namespace:Tobii.InteractionLib.Wpf;assembly=tobii_interaction_lib_wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
When the references are set up, the window can decribe the behaviors of the 3 interactors using IsGazeAware
and HasGaze:
<Window.Resources>
<ResourceDictionary>
<Style x:Key="RectangleWithGazeAwareAnimation" TargetType="Rectangle">
<Setter Property="Fill" Value="LightSkyBlue" />
<Setter Property="Margin" Value="40, 50" />
<Setter Property="wpf:Behaviors.IsGazeAware" Value="True"></Setter>
<Style.Triggers>
<Trigger Property="wpf:Behaviors.HasGaze" Value="True">