Windows IoT Raspberry Pi 3 C#枚举USB音频适配器

Windows IoT Raspberry Pi 3 C#枚举USB音频适配器,c#,audio,raspberry-pi3,windows-iot-core-10,enumerate-devices,C#,Audio,Raspberry Pi3,Windows Iot Core 10,Enumerate Devices,我打算将2个或更多USB音频适配器(每个适配器带有麦克风和线路)连接到我的raspberry pi 3。因此,我需要分别列举音频渲染和音频捕获的音频设备,并将它们显示在类似于的列表框中。 我不明白该怎么办。 我尝试使用下面的代码,出现异常处理程序。 请告知。 谢谢 captureDeviceList=newobserveCollection(); audioCaptureList.ItemsSource=captureDeviceList; renderDeviceList=新的Observab

我打算将2个或更多USB音频适配器(每个适配器带有麦克风和线路)连接到我的raspberry pi 3。因此,我需要分别列举音频渲染和音频捕获的音频设备,并将它们显示在类似于的
列表框中。
我不明白该怎么办。
我尝试使用下面的代码,出现异常处理程序。
请告知。
谢谢

captureDeviceList=newobserveCollection();
audioCaptureList.ItemsSource=captureDeviceList;
renderDeviceList=新的ObservableCollection();
audioRenderList.ItemsSource=renderDeviceList;
专用异步设备()
{
var renderDevices=等待设备信息.FindAllAsync(DeviceClass.AudioRender);
如果(renderDevices.Count>0)
{
对于(var i=0;i0)
{
对于(var i=0;i
更新: 我已经修改了我的XAML代码。。它起作用了。。但似乎我无法正确安排堆栈面板边距。

我的代码在下面。有什么建议吗? 谢谢


更新日期:2017年10月9日


因为没有xaml中的代码,我不确定您的数据绑定方式。导致此问题的原因有几个。请参考下面的源代码,也许您需要进行一些修改以满足您的要求。此外,您应该在页面的标记中添加xmlns:device=“using:Windows.Devices.Enumeration”

<Page
x:Class="AudioInSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AudioInSample"
xmlns:device="using:Windows.Devices.Enumeration"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="White">
    <StackPanel Margin="10" MinWidth="500">

        <ListBox x:Name="audioCaptureList">
            <ListBox.ItemTemplate>
                <DataTemplate  x:DataType="device:DeviceInformation">
                    <StackPanel>
                        <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="12, 15, 12, 0" FontSize="18.667" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ListBox x:Name="audioRenderList">
            <ListBox.ItemTemplate>
                <DataTemplate x:DataType="device:DeviceInformation">
                    <StackPanel>
                        <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="12, 15, 12, 0" FontSize="18.667" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


    </StackPanel>
</Grid>


引发异常的位置?我已尝试使用上述代码,没有异常。能否在xaml中显示audioRenderList和audioCaptureList的数据绑定代码?顺便问一下,您确定代码“captureDeviceList.Add(renderDevices[I]);”您的期望值是多少?根据对变量名的理解,它应该是“renderDeviceList.Add(renderDevices[i]);”我重新开始了覆盆子派。。n设法毫无例外地运行代码…&关于renderdevicelist.add,您是对的。我将编辑该部分。但是,我仍然无法在列表框上显示它们。请在页面(*.xaml文件)中显示列表框元素的代码。是否通过在renderDevices.count和captureDevices.count设置断点来检查设备的计数?某些设备与Raspberry PI不兼容。我设法在列表框上显示。。但它们都显示相同的东西“windows.devices.enumaration.DeviceInformation”。。如何识别和显示详细的设备信息?嗨,Micheal,我在问题中添加了我的xaml代码更新。我会试试你的建议。嗨,Micheal,我已经试过密码了。。它起作用了。。但是,当我更新了我的问题的jpeg时,似乎出现了页边空白问题。可以提供建议吗?在您的页面中,需要修改元素的“边距”值以适应布局。有关边距属性的更多信息,请参考:列表框边距?还是stackpanel的边距?因为我尝试了stackpanel和textblock边距。。没有帮助。请更改列表框的边距。[Margin=“10,28358144”]似乎太大了。
<PivotItem Header="Info">
            <Grid>
                <ListBox x:Name="audioRenderList" Margin="10,28,358,144" Width="250" Height="90">
                    <ListBox.ItemTemplate>
                        <DataTemplate x:DataType="device:DeviceInformation">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <ListBox x:Name="audioCaptureList" Margin="344,28,10,144" Width="250" Height="90">
                    <ListBox.ItemTemplate>
                        <DataTemplate x:DataType="device:DeviceInformation">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <TextBlock x:Name="renderDeviceCount" HorizontalAlignment="Left" Margin="220,4,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40"/>
                <TextBlock x:Name="captureDeviceCount" HorizontalAlignment="Left" Margin="560,4,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40" RenderTransformOrigin="0.425,-0.5"/>
                <TextBlock HorizontalAlignment="Left" Margin="350,4,0,0" TextWrapping="Wrap" Text="Capture Devices" VerticalAlignment="Top"/>
                <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Render Devices" VerticalAlignment="Top" Margin="10,4,0,0"/>
                <ListBox x:Name="usbList" Margin="10,156,358,16" Width="250" Height="90">
                    <ListBox.ItemTemplate>
                        <DataTemplate x:DataType="device:DeviceInformation">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="USB Storage" VerticalAlignment="Top" Margin="10,131,0,0"/>
                <TextBlock x:Name="usbDeviceCount" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="220,131,0,0" Width="40" RenderTransformOrigin="0.575,-0.75"/>

            </Grid>
        </PivotItem>
    </Pivot>
<Page
x:Class="AudioInSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AudioInSample"
xmlns:device="using:Windows.Devices.Enumeration"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="White">
    <StackPanel Margin="10" MinWidth="500">

        <ListBox x:Name="audioCaptureList">
            <ListBox.ItemTemplate>
                <DataTemplate  x:DataType="device:DeviceInformation">
                    <StackPanel>
                        <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="12, 15, 12, 0" FontSize="18.667" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ListBox x:Name="audioRenderList">
            <ListBox.ItemTemplate>
                <DataTemplate x:DataType="device:DeviceInformation">
                    <StackPanel>
                        <TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="12, 15, 12, 0" FontSize="18.667" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


    </StackPanel>
</Grid>