前提・実現したいこと
Tobii SDK 入門の手順に従ってC# WPFアプリケーションを作成しようとしています。
ソリューションのビルドには成功するのですが、プロジェクトの実行を行うと以下のエラーメッセージが発生します。
例外発生個所は「MainWindow.xaml.cs」のInitializeComponent();です。
サンプルが実行できると白いウィンドウが表示されるかと思います。
「MainWindow.xaml」のコメント部分を切り取ると例外が発生せず実行できるので
この部分か関係しているのではないかと考えています。
いろいろ調べておりますが、解決策が見つからず困っております。
もしおわかりの方がおられましたら、ご教授いただけると幸いです。
何卒、よろしくお願い申し上げます。
発生している問題・エラーメッセージ
型 'System.NullReferenceException' の例外が PresentationFramework.dll で発生しましたが、ユーザー コード内ではハンドルされませんでした 追加情報:オブジェクト参照がオブジェクト インスタンスに設定されていません。 この例外のハンドラーがある場合は、プログラムを安全に続行できます。
該当のソースコード
App.xaml.cs
C#
1using System; 2using System.Collections.Generic; 3using System.Configuration; 4using System.Data; 5using System.Linq; 6using System.Threading.Tasks; 7using System.Windows; 8using Tobii.Interaction; 9using Tobii.Interaction.Wpf; 10 11public partial class App : Application 12{ 13 private Host _host; 14 private WpfInteractorAgent _wpfInteractorAgent; 15 16 protected override void OnStartup(StartupEventArgs e) 17 { 18 _host = new Host(); 19 _wpfInteractorAgent = _host.InitializeWpfAgent(); 20 } 21 22 protected override void OnExit(ExitEventArgs e) 23 { 24 _host.Dispose(); 25 base.OnExit(e); 26 } 27}
該当のソースコード
MainWindow.xaml
XAML
1<Window x:Class="Wpf_Tobii_APP.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:Wpf_Tobii_APP" 7 xmlns:tobii="clr-namespace:Tobii.Interaction.Wpf;assembly=Tobii.Interaction.Net" 8 mc:Ignorable="d" 9 Title="MainWindow" Height="350" Width="525"> 10//////////////////////////////////////////////////////////////////////////////// 11 <Grid x:Name="LayoutRoot" 12 tobii:Behaviors.IsGazeAware="True"> 13 <Grid.Style> 14 <Style TargetType="Grid"> 15 <Setter Property="Background" Value="White" /> 16 17 <Style.Triggers> 18 <Trigger Property="tobii:Behaviors.HasGaze" Value="True"> 19 <Setter Property="Background" Value="Magenta" /> 20 </Trigger> 21 </Style.Triggers> 22 </Style> 23 </Grid.Style> 24 </Grid> 25//////////////////////////////////////////////////////////////////////////////// 26</Window>
MainWindow.xaml.cs
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Threading.Tasks; 6using System.Windows; 7using System.Windows.Controls; 8using System.Windows.Data; 9using System.Windows.Documents; 10using System.Windows.Input; 11using System.Windows.Media; 12using System.Windows.Media.Imaging; 13using System.Windows.Navigation; 14using System.Windows.Shapes; 15 16namespace Wpf_Tobii_APP 17{ 18 /// <summary> 19 /// MainWindow.xaml の相互作用ロジック 20 /// </summary> 21 public partial class MainWindow : Window 22 { 23 public MainWindow() 24 { 25 InitializeComponent();//例外発生個所 26 } 27 } 28} 29
呼び出し履歴(スタックトレース)
-
Wpf_Tobii_APP.exe!Wpf_Tobii_APP.MainWindow.MainWindow() 行 25 C#