none
Kinect-chooser Problems(SDK1.7) RRS feed

  • Question

  •  Good Day All 

    I have an example project that navigates from one page to another. The Main Page or rather the first page loaded works well. The Kinect-chooser does not show any warning , i can do the Push to Press. So when i navigate from that page to another page. It seems like the Kinect-chooser loses the Kinect sensor. i have the same code that start the Kinect chooser in the second page for in case it lost the sensor. 

    NB:I have removed the ddl's in the example app just to reduce the size of the example project 

    KinectInteraction170_32.dll
    KinectInteraction170_64.dll 

    i have attached my example project here    

    http://www.dotnetfunda.com/userfiles/QuestionFiles/Vuyiswamb_Question_635001221577285859_Sample.zip

    Thanks 


    Vuyiswa Maseko

    Friday, March 29, 2013 6:52 AM

Answers

  • Good Day 

    I resolved the problem the following way. 

    Step 1 - i created a Static Property that i can access from any page 

           public static KinectSensorChooser GlobalKinectSensorChooser { get; set; }


    Step 2  - On the MainMenu Page i added the following 

              
      this.InitializeComponent();
    
                if (Generics.GlobalKinectSensorChooser == null)
                { 
                    // initialize the sensor chooser and UI
                    this.sensorChooser = new KinectSensorChooser();
                    this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                    this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
                    this.sensorChooser.Start(); 
                    Generics.GlobalKinectSensorChooser = this.sensorChooser;
                }
                else
                {   // initialize the sensor chooser and UI 
                    this.sensorChooser = new KinectSensorChooser();
                    this.sensorChooser = Generics.GlobalKinectSensorChooser;
                    this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                    this.sensorChooserUi.KinectSensorChooser = sensorChooser;  
                }
    
                // Bind the sensor chooser's current sensor to the KinectRegion
                var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
                BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);

     Step 3  - and when i navigate to another page i unsubscribe from the current page's event  navigate 

           this.sensorChooser.KinectChanged -= SensorChooserOnKinectChanged;
                (Application.Current.MainWindow.FindName("_mainFrame") as Frame).Source = new Uri("Game1.xaml", UriKind.Relative);

     

    Step 4 -and when i get to the page constructor on the other side , i get the Sensorchooser from the static property and subscribe to the event again and bind the chooser to the region and it works. 

              
      // initialize the sensor chooser and UI
                this.sensorChooser = new KinectSensorChooser();
                this.sensorChooser = Generics.GlobalKinectSensorChooser; 
                this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                this.sensorChooserUi.KinectSensorChooser = sensorChooser; 
                // Bind the sensor chooser's current sensor to the KinectRegion
                var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
                BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);

    Thanks 


    Vuyiswa Maseko

    Saturday, March 30, 2013 8:42 AM

All replies

  • I haven't looked at your code, but you will have to ensure you are passing the object you created on your main form to the other Window/Pages. Ideally, you want to pass the instance of the KinectSensor or the KinectSensorChooser if using the KinectChooserUI control.

    You could just expose a public KinectSensorChooser property, on your other form, and set this before you show the new Window. If you are creating "new" objects that would be a sign that something is not correct. Additionally, you will have to ensure correct binding of properties.

    Typically you should have something that looks like this on the MainWindow:

            KinectSensorChooser sensorChooser = null;
            public MainWindow()
            {
                InitializeComponent();
                ...
                sensorChooser = new KinectSensorChooser();
                this.SensorChooserUI.KinectSensorChooser = sensorChooser;
                sensorChooser.Start();
                ...
            }

    For you other Window, set its KinectSensorChooser variable to the same sensorChooser.

            private void btnNew_Click(object sender, RoutedEventArgs e)
            {
                SecondWindow sw = new SecondWindow();
                sw.PassedSensorChooser = sensorChooser;
                sw.Show();
            }

    Code for the second Window,

        public partial class SecondWindow : Window
        {
    ...
            private KinectSensorChooser sensorChooser;
            public KinectSensorChooser PassedSensorChooser
            {
                set
                {
                    if (value != null)
                        this.sensorChooser = value;
                    this.SensorChooserUI.KinectSensorChooser = this.sensorChooser;
                }
            }
    ...
    This is a simplified idea to demonstrate a concept. I haven't tested the code, but should give you an idea what you can do. There are other ways you could handle this.


    Friday, March 29, 2013 9:46 PM
  • I tried to use the property to pass the kinectchooser across , but the problem occurs immediately when i navigate , i also failed to state that i am navigation like this 

       (Application.Current.MainWindow.FindName("_mainFrame") as Frame).Source = new Uri("Game1.xaml", UriKind.Relative);

    So i am using a Frame to navigate. but the MainWindow has no kinect code ,it just Marshall the navigation and the pages take cares of Kinect stuff.

    Thanks 


    Vuyiswa Maseko

    Saturday, March 30, 2013 8:26 AM
  • Good Day 

    I resolved the problem the following way. 

    Step 1 - i created a Static Property that i can access from any page 

           public static KinectSensorChooser GlobalKinectSensorChooser { get; set; }


    Step 2  - On the MainMenu Page i added the following 

              
      this.InitializeComponent();
    
                if (Generics.GlobalKinectSensorChooser == null)
                { 
                    // initialize the sensor chooser and UI
                    this.sensorChooser = new KinectSensorChooser();
                    this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                    this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
                    this.sensorChooser.Start(); 
                    Generics.GlobalKinectSensorChooser = this.sensorChooser;
                }
                else
                {   // initialize the sensor chooser and UI 
                    this.sensorChooser = new KinectSensorChooser();
                    this.sensorChooser = Generics.GlobalKinectSensorChooser;
                    this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                    this.sensorChooserUi.KinectSensorChooser = sensorChooser;  
                }
    
                // Bind the sensor chooser's current sensor to the KinectRegion
                var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
                BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);

     Step 3  - and when i navigate to another page i unsubscribe from the current page's event  navigate 

           this.sensorChooser.KinectChanged -= SensorChooserOnKinectChanged;
                (Application.Current.MainWindow.FindName("_mainFrame") as Frame).Source = new Uri("Game1.xaml", UriKind.Relative);

     

    Step 4 -and when i get to the page constructor on the other side , i get the Sensorchooser from the static property and subscribe to the event again and bind the chooser to the region and it works. 

              
      // initialize the sensor chooser and UI
                this.sensorChooser = new KinectSensorChooser();
                this.sensorChooser = Generics.GlobalKinectSensorChooser; 
                this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
                this.sensorChooserUi.KinectSensorChooser = sensorChooser; 
                // Bind the sensor chooser's current sensor to the KinectRegion
                var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
                BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);

    Thanks 


    Vuyiswa Maseko

    Saturday, March 30, 2013 8:42 AM