* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
3.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Paint an Area with a Video | 03/30/2017 |
|
|
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.
Example
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]
Example
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.