我有一个列表视图,它显示了使用 WPFMediaKit 的系统识别的所有相机的小预览。
这是我的代码:
Window4.xaml
<Window x:Class="SampleApplication.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WPFMediaKit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
Title="Window4" Height="300" Width="300">
<Window.Resources>
<Style x:Key="CamerasLVStyle" TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border
x:Name="bd" >
<ScrollViewer>
<WrapPanel
ItemWidth="75"
ItemHeight="65"
IsItemsHost="True"
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}}}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CamerasLVItem" TargetType='{x:Type ListViewItem}' BasedOn='{StaticResource {x:Type ListBoxItem}}'>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="0,0,0,0"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Border
Background="#FF1E2225">
<WPFMediaKit:VideoCaptureElement x:Name="videoCapElement"
LoadedBehavior="Play"
VideoCaptureDevice="{Binding}"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListView x:Name="CamerasList"
Grid.Column="1"
Background="{x:Null}"
SelectionMode="Single"
ItemsSource="{Binding Cameras}"
Style="{StaticResource CamerasLVStyle}"
ItemContainerStyle="{StaticResource CamerasLVItem}"/>
</Grid>
Window4.xam.cs
public partial class Window4 : Window
{
private List<DsDevice> _cameras;
public List<DsDevice> Cameras
{
get { return _cameras; }
set { _cameras = value; }
}
public Window4()
{
InitializeComponent();
Cameras = MultimediaUtil.VideoInputDevices.ToList();
this.DataContext = this;
}
}
在某些电脑上工作正常并显示所有相机,但在其他一些电脑上则没有。
例如,我有一个带有集成网络摄像头和 Microsoft LifeCam Cinema 的 Windows 8.1 笔记本电脑。
有时它显示第一个,有时它显示第二个,但绝不会同时显示两者(两个黑色方块出现,但只显示一个流)。
有什么建议吗?谢谢。