none
Stop Tracking when jump to previous window RRS feed

  • Question

  • I have a back button on current window when i clicked on back button, previous window showed but tracking is not happening . and line that is in comment, when i uncomment and run my code then it will give "{"Object reference not set to an instance of an object."}"

    CurrentWindow.xaml.cs

            private void KinectTileButton_Click(object sender, RoutedEventArgs e)
            {
             
                Previous exm = new previous();
                //exm.sensorChooser.Kinect.Stop();
                exm.Show();
                this.Close();
            }

    Previous.xaml.cs

    private void KinectTileButton_Click_5(object sender, RoutedEventArgs e)
            {
    
              
                CurrentWindow exe = new CurrentWindow(sensorChooser);
                exe.Show();
                this.Close();
            }
    

    Waiting for your solution

    Monday, December 1, 2014 6:57 PM

Answers

  • When you navigate to and from external windows, you have to ensure you are maintaining the state of the sensor and ensure you have initialized the components when those windows are reloaded. This is more an issue with how your application is architected then with how the components are operating.

    The code you provided just shows how you have navigated are handling a button click event. The Kinect will not have any knowledge of your windows or how you are intending to use the components. You need to set the KinectRegion control's KinectSensorChooser property to use the correct version of the sensor chooser.


    Carmine Sirignano - MSFT

    Monday, December 1, 2014 10:55 PM

All replies

  • When you navigate to and from external windows, you have to ensure you are maintaining the state of the sensor and ensure you have initialized the components when those windows are reloaded. This is more an issue with how your application is architected then with how the components are operating.

    The code you provided just shows how you have navigated are handling a button click event. The Kinect will not have any knowledge of your windows or how you are intending to use the components. You need to set the KinectRegion control's KinectSensorChooser property to use the correct version of the sensor chooser.


    Carmine Sirignano - MSFT

    Monday, December 1, 2014 10:55 PM
  • All the sensor componemt are properly initialized in Previous.Xaml.cs.  and i mention in above code, object of kinectsenosr is passed in the constructor of CurrentWindow. In other word utillizing the component of Previous window in CurrentWindow.

    Previous.Xaml.cs

            public  KinectSensorChooser sensorChooser;
            public Previous()
            {
                InitializeComponent();
                Loaded += OnLoaded;
            }
    private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
            {
    
                this.sensorChooser = new KinectSensorChooser();
                this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
                this.sensorChooser.Start();
    
            }

    CurrentWindow.xaml.cs

            public CurrentWindow(KinectSensorChooser sensorChooser, string BtnName)
            {
                
                InitializeComponent();
           
               
                sensorChooser.Kinect.SkeletonStream.Enable();
                sensorChooser.Kinect.DepthStream.Enable();
                
                sensorChooser.KinectChanged += new EventHandler<KinectChangedEventArgs>(SensorChooserOnKinectChanged);
                sensorChooserUi.KinectSensorChooser = sensorChooser;
               sensorChooser.Kinect.SkeletonFrameReady += TrackSkeleton;
               sensorChooser.Kinect.DepthFrameReady += new EventHandler<DepthImageFrameReadyEventArgs>(sensor_DepthFrameReady);
                sensorChooser.Kinect.Start();
                
            }

    Tell me what i changed in code ?

    Tuesday, December 2, 2014 5:45 AM
  • On Current page you do not re-initialize the sensorChooser.Kinect properties, this should all be done on Previous.Xaml. I don't see you doing that in the code you provided. Once you have configured the sensorChooser object, you also need to configure the KinectRegion.SensorChooser object on both Current and Previous pages. Again, you are not doing this in the code you provided. Move your depthstream/skeleton.enabled calls to the MainWindow that is loaded for the application. Also, take very special care of how you are subscribing to events(see WPF documentation) because if you continuously subscribe to the same event you will cause a memory leak.

    Look at your Xaml and see what name you assigned for the KinectRegion control. To make it obvious name one currectKinectRegion and the other previousKinectRegion. On the loaded event of each Window, set the currectKinectRegion.SensorChooser = sensorChooser.


    Carmine Sirignano - MSFT





    Tuesday, December 2, 2014 7:46 PM
  • Can you tell me the difference between SensorChooser and sensorChooser? 
    Saturday, December 6, 2014 12:10 PM
  • SensorChoose is a property where sensorChooser is a variable

    Carmine Sirignano - MSFT

    Wednesday, December 10, 2014 8:15 PM