private void InputWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            var id = args.Id;

            // you could use DeviceInformation directly here, using the
            // CreateFromIdAsync method. However, that is an async method
            // and so adds a bit of delay. I'm using a trimmed down object
            // to hold MIDI information rather than using the DeviceInformation class

#if DEBUG
            // this is so you can see what the properties contain
            //foreach (var p in args.Properties.Keys)
            //{
            //    System.Diagnostics.Debug.WriteLine("Input: " + args.Name + " : " + p + " : " + args.Properties[p]);
            //}
#endif

            var info = new MidiDeviceInformation();
            info.Id        = id;
            info.Name      = args.Name;
            info.IsDefault = args.IsDefault;
            info.IsEnabled = args.IsEnabled;

            ConnectedInputDevices.Add(info);

            // notify clients
            if (InputDevicesChanged != null)
            {
                InputDevicesChanged(this, new EventArgs());
            }
        }
        private void InputWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            // remove from our collection the item with the specified ID

            var id = args.Id;

            var toRemove = (from MidiDeviceInformation mdi in ConnectedInputDevices
                            where mdi.Id == id
                            select mdi).FirstOrDefault();

            if (toRemove != null)
            {
                ConnectedInputDevices.Remove(toRemove);

                // notify clients
                if (InputDevicesChanged != null)
                {
                    InputDevicesChanged(this, new EventArgs());
                }
            }
        }