コード例 #1
0
        /// <summary>
        /// Get the first controller, Add the gamepad added and disconnected events.
        /// </summary>
        private void InitiateGamepad()
        {
            Gamepad.GamepadAdded += (object sender, Gamepad e) =>
            {
                lock (myLock)
                {
                    mainGamepad    = e;
                    xboxController = true;
                }
            };

            Gamepad.GamepadRemoved += (object sender, Gamepad e) =>
            {
                lock (myLock)
                {
                    mainGamepad    = null;
                    xboxController = false;
                }
            };

            lock (myLock)
            {
                // Find the first gamepad.
                foreach (var gamepad in Gamepad.Gamepads)
                {
                    if (!mainGamepad.Equals(gamepad))
                    {
                        mainGamepad    = gamepad;
                        xboxController = true;
                        break;
                    }
                }
            }
        }
コード例 #2
0
 private void Gamepad_GamepadRemoved(object sender, Gamepad e)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(() =>
     {
         if (e.Equals(GamePad))
         {
             GamePad = null;
         }
         if (GamePadCollection.Contains(e))
         {
             GamePadCollection.Remove(e);
         }
     });
 }