我正在尝试更改窗口中 TextBlock 的文本。我不断收到 NullReferenceException。我该如何解决?
欢迎.xaml
<TextBlock x:Name="StartNotice" HorizontalAlignment="Left" Margin="247,252,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.595,0.627"
Text="Say "abracadabra" to start ." FontStyle="Italic"
TextAlignment="Center" Foreground="Purple" Width="150"/>
欢迎.xaml.cs
private void Page_Loaded(object sender, RoutedEventArgs e)
{
MainWindow mainWindow=new MainWindow();
mainWindow.DataContext=this;
mainWindow.Show();
}
主窗口.xaml.cs
try
{
myKinect=KinectSensor.KinectSensor[0];
}
catch
{
Welcome welcomePage=(Welcome)this.DataContext();
welcomePage.StartNotice.Text="Please connect a Kinect";
}