显示 AudioCaptureDevices 的组合框
我想在代码(无 XAML)中创建一个 ComboBox
控件,它显示可用 AudioCaptureDevice
的列表。
ReadOnlyCollection<AudioCaptureDevice> audioDevices;
audioDevices = CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();
StackPanel sp = new StackPanel();
ComboBox cbxAudioDevices = new ComboBox();
cbxAudioDevices.ItemsSource = audioDevices;
sp.Children.Add(cbxAudioDevices);
this.RootVisual = sp;
但是,只显示名为 System.Windows.Media.AudioCaptureDevice 的条目,而不是显示漂亮的名称。 漂亮的名称可以通过 AudioCaptureDevice
的 FriendlyName
属性获得。
有没有一种简单的方法来转换我的集合,以便它显示友好名称,但仍保留 AudioCaptureDevice
?或者我是否必须创建仅包含名称的第二个集合,然后使用原始集合来获取其他属性?
I want to create a ComboBox
control in code (no XAML) which displays the list of available AudioCaptureDevice
s.
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 AudioCaptureDevice
s? Or will I have to create a second collection with only the names, and then take my original collection to get the other properties?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要指定一个 DataTemplate 来帮助呈现 AudioCaptureDevice 对象。您可以在代码中执行此操作,如此处所示。您将使用该 DataTemplate 并将其分配给 ComboBox 的 ItemTemplate 属性。
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.