CaptureElement CaptureElement CaptureElement CaptureElement Class

Definition

Renders a stream from a capture device, such as a camera or webcam. CaptureElement is used in conjunction with the Windows.Media.Capture.MediaCapture API, and must be hooked up in the code behind.

public : sealed class CaptureElement : FrameworkElement, ICaptureElementpublic sealed class CaptureElement : FrameworkElement, ICaptureElementPublic NotInheritable Class CaptureElement Inherits FrameworkElement Implements ICaptureElement// This API is not available in Javascript.
<CaptureElement .../>
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Inherited Members

Inherited properties

Inherited events

Inherited methods

Examples

Here's some code that shows how to capture video from a camera with a MediaCapture control and display the preview with the CaptureElement.

<StackPanel>
    <CaptureElement x:Name="myCaptureElement"         
                    Width="320" Height="240"/>
    <Button Click="Button_Click">Click me to see a preview</Button>
</StackPanel>

// You must specify capabilities for Webcam and Microphone in your
// app manifest for this code to work.

private async void Button_Click(object sender, RoutedEventArgs e) 
{           
    // Using Windows.Media.Capture.MediaCapture APIs 
    // to stream from webcam
    MediaCapture mediaCaptureMgr = new MediaCapture();
    await mediaCaptureMgr.InitializeAsync();

    // Start capture preview.                
    myCaptureElement.Source = mediaCaptureMgr;
    await mediaCaptureMgr.StartPreviewAsync();
}

Remarks

CaptureElement is used in conjunction with the Windows.Media.Capture.MediaCapture API. Make sure your project has specified device capabilities for Webcam and Microphone to use this API. For more info on how to use CaptureElement, see Capture photos and video with MediaCapture.

Use the MediaCapture object to control the stream and set options on the capture device. The CaptureElement is the UI portion of the stream that is associated with the MediaCapture.

You can use at most one CaptureElement to render a stream from a single capture device.

Note

If your app manually sets the size of the CaptureElement control, you must make sure that the dimensions of the control do not exceed the device's native display resolution.

Constructors

CaptureElement() CaptureElement() CaptureElement() CaptureElement()

Initializes a new instance of the CaptureElement class.

public : CaptureElement()public CaptureElement()Public Sub New()// This API is not available in Javascript.

Properties

Source Source Source Source

Gets or sets the source MediaCapture that this CaptureElement represents.

public : MediaCapture Source { get; set; }public MediaCapture Source { get; set; }Public ReadWrite Property Source As MediaCapture// This API is not available in Javascript.

Remarks

This property should not be set in XAML, because XAML represents initial state, and there is no good way to reference a MediaCapture through XAML resources. Initializing a MediaCapture is typically done by async operations or only when a capture is about to begin.

Important

You should always set the Source property to null when you are shutting down media capture in your app. For more information on properly cleaning up media capture resources, see Capture photos and video with MediaCapture.

SourceProperty SourceProperty SourceProperty SourceProperty

Identifies the Source dependency property.

public : static DependencyProperty SourceProperty { get; }public static DependencyProperty SourceProperty { get; }Public Static ReadOnly Property SourceProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the Source dependency property.

Stretch Stretch Stretch Stretch

Gets or sets how content from Source is resized to fill its allocated space, as declared by the Height and Width properties of the CaptureElement.

public : Stretch Stretch { get; set; }public Stretch Stretch { get; set; }Public ReadWrite Property Stretch As Stretch// This API is not available in Javascript.
<CaptureElement Stretch="stretchMemberName" />
Value
Stretch Stretch Stretch Stretch

A value of the enumeration.

StretchProperty StretchProperty StretchProperty StretchProperty

Identifies the Stretch dependency property.

public : static DependencyProperty StretchProperty { get; }public static DependencyProperty StretchProperty { get; }Public Static ReadOnly Property StretchProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the Stretch dependency property.

See Also