Events

RadWebCam exposes the following events, specific for the control

SnapshotTaken

The SnapshotTaken event fires when the "Take snapshot" button is pressed or when you call the TakeSnapshot method of RadWebCam.

The purpose of the event is to notify you that a snapshot has been taken and you need to take action, like saving it to a file.

The event arguments are of type SnapshotTakenEventArgs which exposes a Snapshot property (of type BitmapSource).

Example 1: Subscribing to the SnapshotTaken event

public MainWindow() 
{ 
    InitializeComponent();       
    this.radWebCam.SnapshotTaken += RadWebCam_SnapshotTaken; 
} 
 
private void RadWebCam_SnapshotTaken(object sender, SnapshotTakenEventArgs e) 
{ 
    BitmapSource snapshot = e.Snapshot; 
    // here you save the source to a file, in memory, or to show it in the UI 
} 

CameraError

The CameraError event fires when one of the expected camera errors appears.

The event can be used to notify you about the corresponding error, or to replace the error message shown in the control.

The event arguments are of type CameraErrorEventArgs and they expose an Error property that contains information about the error. The Error property is of type ErrorInfo which gives you access to the message and state of the error via the Message and ErrorState properties.

Example 2: Subscribing to the CameraError event and replacing the no-camera error message

public MainWindow() 
{ 
    InitializeComponent(); 
    this.radWebCam.CameraError += RadWebCam_CameraError; 
} 
 
private void RadWebCam_CameraError(object sender, RoutedEventArgs e) 
{ 
    var args = (CameraErrorEventArgs)e; 
    if (args.Error.ErrorState == CameraErrorState.NoCamera) 
    { 
        args.Error.Message = "Cannot detect a camera device."; 
    }            
} 

Figure 1: Customized error message

See Also

In this article
Not finding the help you need? Improve this article