public MainWindow()
        {
            Thread.CurrentThread.Name = "KillersWearsPrada-Main Thread";
            Helpers.ResourcesHelper.SaveCurrentDirectory();
            Helpers.ResourcesHelper.ModifyMainBackgroundPath();
            
            modifyAllPath();
            Helpers.SketchHelper.SetDirectories();
            InitializeComponent();

            this.DataContext = this;

            KinectRegion.SetKinectRegion(this, kinectRegion);

            App wvApp = ((App)Application.Current);
            wvApp.KinectRegion = kinectRegion;

            // Use the default sensor
            this.kinectRegion.KinectSensor = KinectSensor.GetDefault();
            attGameController = new GameController(this.kinectRegion.KinectSensor);
            //attKinectInterrogator = new Controller.KinectInterrogator(this.kinectRegion.KinectSensor, REFRESH_TIME);

            attGameController.GetResumeGame.ResumeGameEvent += CaptureResumeGameEvent;
            attGameController.GetUnloadGame.UnloadGameEvent += CaptureUnloadGameEvent;
            attGameController.GetUpdateInventory.UpdateInventoryEvent += CaptureUpdateInventoryEvent;
            attGameController.GetNotifyItemException.NotifyItemExceptionEvent += CaptureNotifyItemException;

            attResumeGameHandlerDelegate = new ResumeGameHandler(this.ResumeGame);
            attUnloadGameHandlerDelegate = new UnloadGameHandler(this.UnloadGame);
            attUpdateInventoryDelegate = new UpdateInventorydHandler(this.UpdateInventory);
            attNotifyItemExceptionDelegate = new NotifyItemExceptionHandler(this.NotifyItemException);
            
        }
        /// <summary>
        /// Called by the delegate <see cref="UpdateInventorydHandler"/> to handle the event <see cref="GameController.UpdateInventory"/> 
        /// that occure when an item is added to the inventory
        /// </summary>
        /// <param name="Parameters">Instance of an object repressenting the class <see cref="GameController.UpdateInventory.Arguments"/> 
        /// which contains information passed by the event <see cref="GameController.UpdateInventory"/></param>
        private void UpdateInventory(GameController.UpdateInventory.Arguments Parameters)
        {
            string cosamostrare = "Item added in Inventory";
            bool wasActualRoom = false;
            foreach (Model.Room r in attGameController.Game.Rooms)
            {
                foreach (Model.Item item in r.Items)
                    if (item.BarCode == Parameters.BarCode)
                    {
                        //Find the button to animate
                        foreach (Button b in room.listOfButtons)
                        {
                            if (b.Tag.ToString() == Parameters.BarCode && attGameController.Game.ActualRoom.Name == r.Name)
                            {
                                //animation!!!
                                VisualStateManager.GoToState(b, "Moving", true);
                                wasActualRoom = true;
                                break;
                            }

                        }

                        //if the animation cannot be performed, a popup is shown
                        if (wasActualRoom == false)
                        {
                            cosamostrare = "Item " + item.ItemName + " added in Inventory";
                            Popup lastc = new Popup(cosamostrare);
                            mainGrid.Children.Add(lastc);
                            lastc.Focus();
                        }

                    }
                if (r.IsRoomCompleted == true && r.IsLastClueAlreadyShown == false)
                {
                    cosamostrare = r.LastClue;
                    Popup lastc = new Popup(cosamostrare);
                    mainGrid.Children.Add(lastc);
                    lastc.Focus();
                    changeDoorColor();
                }
            }
        }
 private void NotifyItemException(GameController.NotifyItemException.Arguments Parameters)
 {
     Popup it = new Popup(Parameters.Messagge);
     mainGrid.Children.Add(it);
     it.Focus();
 }
        /// <summary>
        /// Called by the delegate <see cref="UnloadGameHandler"/> to handle the event <see cref="GameController.UnloadGame"/> 
        /// that occure when the <see cref="Model.Game"/> must be saved and unloaded
        /// </summary>
        /// <param name="Parameters">Instance of an object repressenting the class <see cref="GameController.UnloadGame.Arguments"/> 
        /// which contains information passed by the event <see cref="GameController.UnloadGame"/></param>
        private void UnloadGame(GameController.UnloadGame.Arguments Parameters)
        {
            txtDisplay.IsEnabled = true;
          //  txtDisplay.Visibility = Visibility.Visible;
            txtDisplay.Text = Thread.CurrentThread.Name + " --- Unload";

            disable_Buttons_Labels();

            title_game.Visibility = Visibility.Visible;

            ib = null;
            backgroundPath = Application.Current.Resources[E_GenericImages.Application_Start_Image.ToString()].ToString();
            ib = new ImageBrush();
            ib.ImageSource = new BitmapImage(new Uri(@backgroundPath, UriKind.Absolute));
            this.Background = ib;

            mainGrid.Children.Remove(startRoom);
            mainGrid.Children.Remove(room);
 
            startRoom = null;
            room = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            this.Background.Opacity = 1;
            
            Delete_Sketches_Files_On_Unload();

            /*System.Windows.Forms.Application.Restart();
            Thread.Sleep(2000);
            Application.Current.Shutdown();*/
        }
        /// <summary>
        ///  Called by the delegate <see cref="ResumeGameHandler"/> to handle the event <see cref="GameController.ResumeGame"/> 
        /// that occure when the <see cref="Model.Game"/> must loaded
        /// </summary>
        /// <param name="Parameters">Instance of an object repressenting the class <see cref="GameController.ResumeGame.Arguments"/> 
        /// which contains information passed by the event <see cref="Controller.GameController.ResumeGame"/></param>
        private void ResumeGame(GameController.ResumeGame.Arguments Parameters)
        {
            //Delete_Sketches_Files();
            Delete_Sketches_Files_On_Resume();
            txtDisplay.IsEnabled = true;
            txtDisplay.Visibility = Visibility.Visible;
            txtDisplay.Text = Thread.CurrentThread.Name + " --- Resume  --------";
            txtDisplay.AppendText("\r\n" + attGameController.Game.IsGameStarted.ToString());

            ResumeGameMethod();
            
        }
 private void CaptureUnloadGameEvent(object Sender, GameController.UnloadGame.Arguments Parameters)
 {
     //object[] wvParameters = new object[] { Parameters };
     if (this.Dispatcher.CheckAccess())
     {
         attUnloadGameHandlerDelegate.Invoke(Parameters);
     }
     else
     {
         this.Dispatcher.Invoke(attUnloadGameHandlerDelegate, Parameters);
     }
 }
 private void CaptureUpdateInventoryEvent(object Sender, GameController.UpdateInventory.Arguments Parameters)
 {
     //object[] wvParameters = new object[] { Parameters };
     //this.Invoke(d, new object[] { e });
     if (this.Dispatcher.CheckAccess())
     {
         attUpdateInventoryDelegate.Invoke(Parameters);
     }
     else
     {
         this.Dispatcher.Invoke(attUpdateInventoryDelegate, Parameters);
     }
 }
 private void CaptureNotifyItemException(object sender, GameController.NotifyItemException.Arguments Parameters)
  {
      if (this.Dispatcher.CheckAccess())
      {
          attNotifyItemExceptionDelegate.Invoke(Parameters);
      }
      else
      {
          this.Dispatcher.Invoke(attNotifyItemExceptionDelegate, Parameters);
     }
  }