I have a listview that shows little previews of all the cameras recognized by system using WPFMediaKit.
This is my code:
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;
}
}
At some pcs works fine and shows all cameras, but in some others no.
For example, I have a Windows 8.1 notebook with an integrated webcam and a Microsoft LifeCam Cinema.
Some times it shows the first, some times it shows the second, but never both at the same time (both black squares appears but only one stream is shown).
Any advice? Thanks.