private void Root_Loaded(object sender, RoutedEventArgs e) { if (Dispatcher != null) { Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (SendOrPostCallback) delegate { vidDevice = new CapDevice(null); if (cbDevices.Items.Count > 0) { cbDevices.ItemsSource = null; } bool isDevices = vidDevice.Monikercheck(); //performs initial device check List <ComboMonikers> listDev = new List <ComboMonikers>(); //initiates the list of items if (!isDevices) { MessageBox.Show("No video capture device detected, please connect one and press refresh."); statusList.Insert(0, DateTime.Now.ToString("hh:mm:ss") + " - No video devices found!."); } else if (isDevices) { devList = vidDevice.DeviceList(); foreach (FilterInfo device in devList) { listDev.Add(new ComboMonikers(device.Name, device.MonikerString)); } } cbDevices.DisplayMemberPath = "_Name"; cbDevices.SelectedValuePath = "_Moniker"; cbDevices.ItemsSource = listDev; cbDevices.SelectedIndex = 0; statusList.Insert(0, DateTime.Now.ToString("hh:mm:ss") + " - Populated available video devices."); vidDevice.Stop(); }, null); lbStatus.ItemsSource = statusList; statusList.CollectionChanged += statusList_Sourceupdated; } }
private void btnCamSet_Click(object sender, RoutedEventArgs e) { if (imgStream.Source != null) { MessageBox.Show("Please disconnect the currently active video source first."); } else if (imgStream.Source == null) { try { currentCapDev = cbDevices.Text; moniker = cbDevices.SelectedValue.ToString(); vidDevice = new CapDevice(moniker); //re-initialises the capture device with chosen moniker. vidDevice.OnNewBitmapReady += new EventHandler(_device_OnNewBitmapReady); statusList.Insert(0, DateTime.Now.ToString("hh:mm:ss") + " - Connected to " + currentCapDev + "."); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }