namespace WebcamSL4
{
public partial class MainPage : UserControl
public MainPage()
InitializeComponent();
DataContext = new MainPageViewModel();
}
namespace WebcamSL4.ViewModel
public class MainPageViewModel : ViewModelBase
public MainPageViewModel()
StartWebcamCommand = new RelayCommand(StartWebcam);
StopWebcamCommand = new RelayCommand(StopWebcam);
Video = new VideoBrush();
Video.Stretch = Stretch.UniformToFill;
private CaptureSource _captureSource = new CaptureSource();
public RelayCommand StartWebcamCommand { get; private set; }
public RelayCommand StopWebcamCommand { get; private set; }
public VideoBrush Video { get; private set; }
private void StartWebcam()
if (CaptureDeviceConfiguration.RequestDeviceAccess())
_captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
Video.SetSource(_captureSource);
_captureSource.Start();
private void StopWebcam()
if (_captureSource.State == CaptureState.Started)
_captureSource.Stop();
< UserControl x : Class ="WebcamSL4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
< Grid x : Name ="LayoutRoot" Background ="White">
< Button
Content="Start"
Height="23"
HorizontalAlignment="Left"
Margin="12,265,0,0"
Name="button1"
VerticalAlignment="Top"
Width="75"
Command="{Binding Path=StartWebcamCommand}"/>
< Rectangle
Height="238"
Margin="12,12,0,0"
Name="rectangle1"
Stroke="Black"
StrokeThickness="1"
Width="376"
Fill="{Binding Path=Video}">
</ Rectangle >
Command="{Binding Path=StopWebcamCommand}"
Content="Stop"
Margin="93,265,0,0"
Name="button2"
Width="75" />
</ Grid >
</ UserControl >