private void ButtonBackToMenu(object sender, RoutedEventArgs e)
        {
            if (lightSensor != null)
            {
                lightSensor.ReadingChanged -= LightSensorReadingChanged;
            }

            PeriodicTimer.Cancel2();

            stackpanel4.Visibility = Visibility.Collapsed;
            stackpanel2.Visibility = Visibility.Visible;
        }
        /// <summary>
        /// Unregister from App events and DeviceWatcher events because this page will be unloaded.
        /// </summary>
        protected override void OnNavigatedFrom(NavigationEventArgs eventArgs)
        {
            if (lightSensor != null)
            {
                lightSensor.ReadingChanged -= LightSensorReadingChanged;
            }
            PeriodicTimer.Cancel2();

            DisconnectFromDeviceClick(null, null);

            StopDeviceWatchers();
            StopHandlingAppEvents();

            // We no longer care about the device being connected
            EventHandlerForDevice.Current.OnDeviceConnected = null;
            EventHandlerForDevice.Current.OnDeviceClose     = null;

            IsNavigatedAway = true;
            CancelAllIoTasks();
        }