Errors

This article demonstrates how to customize the error content shown when one of the few known camera errors appear.

When one of the following errors appear, the camera buttons and player get replaced by an error message presenter.

Error Types

There are few expected errors that could appear using the control.

  • No camera detected. This error appears when there is no camera device connected to the computer.

  • The camera is unavailable. This error appears when another application is using the camera device.

  • Video adapter does not support the D3DFMT_X8R8G8B8 format. This error appears when the hardware that runs the RadWebCam control doesn't support the camera rendering engine.

Replacing the Error Message

To replace the error message use the CameraError event of RadWebCam. The CameraErrorEventArgs give access to an ErrorInfo object, which contains information about the error state and message. Use the event to replace the default message with a custom one.

Example 1: 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

Customizing the Error Content Template

By default the error message is displayed in a simple content presenter. To customize this, use the CameraErrorContentTemplate property of RadWebCam.

Example 2: Customizing the error template

<telerik:RadWebCam> 
    <telerik:RadWebCam.CameraErrorContentTemplate> 
        <DataTemplate> 
            <TextBlock Text="{Binding Message}"  
                       Background="#5D6B99"  
                       Foreground="White" 
                       Padding="10" /> 
        </DataTemplate> 
    </telerik:RadWebCam.CameraErrorContentTemplate> 
</telerik:RadWebCam> 

Figure 2: Custom error template

See Also

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