* Updated H2 headings for US-1889327. * Review edits. * Apply suggestions from code review Co-authored-by: Andy (Steve) De George <[email protected]>
3.9 KiB
title, description, ms.date, ms.custom, dev_langs, helpviewer_keywords, ms.assetid
| title | description | ms.date | ms.custom | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| How to: Paint an Area with a Video | Learn how to Paint an Area with a Video. | 03/30/2017 | devdivchpfy22 |
|
|
04dd6600-4a6e-4b43-a93e-21cce7dfbcb8 |
How to: Paint an Area with a Video
This example shows how to paint an area with media. One way to paint an area with media is to use a xref:System.Windows.Controls.MediaElement together with a xref:System.Windows.Media.VisualBrush. Use the xref:System.Windows.Controls.MediaElement to load and play the media, and then use it to set the xref:System.Windows.Media.VisualBrush.Visual%2A property of the xref:System.Windows.Media.VisualBrush. You can then use the xref:System.Windows.Media.VisualBrush to paint an area with the loaded media.
Use a MediaElement with a VisualBrush
The following example uses a xref:System.Windows.Controls.MediaElement and a xref:System.Windows.Media.VisualBrush to paint the xref:System.Windows.Controls.TextBlock.Foreground%2A of a xref:System.Windows.Controls.TextBlock control with video. This example sets the xref:System.Windows.Controls.MediaElement.IsMuted%2A property of the xref:System.Windows.Controls.MediaElement to true so that it produces no sound.
[!code-csharpVisualbrush_markup_snip#GraphicsMMVideoAsTextBackgroundInline] [!code-vbVisualbrush_markup_snip#GraphicsMMVideoAsTextBackgroundInline] [!code-xamlVisualbrush_markup_snip#GraphicsMMVideoAsTextBackgroundInline]
Use the VisualBrush with the loaded media
Because xref:System.Windows.Media.VisualBrush inherits from the xref:System.Windows.Media.TileBrush class, it provides several tiling modes. By setting the xref:System.Windows.Media.TileBrush.TileMode%2A property of a xref:System.Windows.Media.VisualBrush to xref:System.Windows.Media.TileMode.Tile and by setting its xref:System.Windows.Media.TileBrush.Viewport%2A property to a value smaller than the area that you are painting, you can create a tiled pattern.
The following example is identical to the previous example, except that the xref:System.Windows.Media.VisualBrush generates a pattern from the video.
[!code-csharpVisualbrush_markup_snip#GraphicsMMVideoAsTextBackgroundTiledInline] [!code-vbVisualbrush_markup_snip#GraphicsMMVideoAsTextBackgroundTiledInline] [!code-xamlVisualbrush_markup_snip#GraphicsMMVideoAsTextBackgroundTiledInline]
For information about how to add a content file, such as a media file, to your application, see WPF Application Resource, Content, and Data Files. When you add a media file, you must add it as a content file, not as a resource file.