显示 AudioCaptureDevices 的组合框

发布于 2024-10-25 07:56:13 字数 694 浏览 1 评论 0原文

我想在代码(无 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 的条目,而不是显示漂亮的名称。 漂亮的名称可以通过 AudioCaptureDeviceFriendlyName 属性获得。

有没有一种简单的方法来转换我的集合,以便它显示友好名称,但仍保留 AudioCaptureDevice ?或者我是否必须创建仅包含名称的第二个集合,然后使用原始集合来获取其他属性?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2024-11-01 07:56:13

您需要指定一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文