CaptureElement CaptureElement CaptureElement Class

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

Syntax

Declaration

public sealed class CaptureElementpublic sealed class CaptureElementPublic NotInheritable Class CaptureElement
<CaptureElement .../>

Inheritance Hierarchy

Inherited Members

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Tag
Tag
Tag
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Remarks

CaptureElement is used in conjunction with the 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.

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();
}

Constructors summary

Initializes a new instance of the CaptureElement class.

Properties summary

Gets or sets the source MediaCapture that this CaptureElement represents.

Identifies the Source dependency property.

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.

Identifies the Stretch dependency property.

Constructors

  • CaptureElement()
    CaptureElement()
    CaptureElement()
    CaptureElement()

    Initializes a new instance of the CaptureElement class.

    public CaptureElement()public CaptureElement()Public Function CaptureElement() As

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

    Property Value

    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

    Property Value

  • 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
    <CaptureElement Stretch="stretchMemberName" />
    

    Property Value

  • 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

    Property Value

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll