0

I want to create a ComboBox control in code (no XAML) which displays the list of available AudioCaptureDevices.

ReadOnlyCollection<AudioCaptureDevice> audioDevices;
audioDevices = CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();

StackPanel sp = new StackPanel();
ComboBox cbxAudioDevices = new ComboBox();
cbxAudioDevices.ItemsSource = audioDevices;
sp.Children.Add(cbxAudioDevices);
this.RootVisual = sp;

However, instead of displaying nice-looking names, only entries named System.Windows.Media.AudioCaptureDevice are shown. The nice-looking names would be available through the FriendlyName property of the AudioCaptureDevice.

Is there an easy way to convert my collection so that it will display the friendly names, but will still hold the AudioCaptureDevices? Or will I have to create a second collection with only the names, and then take my original collection to get the other properties?

Etan
  • 17,014
  • 17
  • 89
  • 148

1 Answers1

1

You need to specify a DataTemplate to help present the AudioCaptureDevice objects. You can do this in code as illustrated here. You would use that DataTemplate and assign it to your ComboBox's ItemTemplate property.

Community
  • 1
  • 1
Rus
  • 1,827
  • 1
  • 21
  • 32