I have a question about binding to a visual brush visual. If I define it in XAML it works. If I define the the same thing programmatically then it does not work. Here is an example.
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="MyWindow"
Title="MainWindow" Height="350" Width="525">
<Grid >
<Rectangle Height="299" Width="400" Stroke="Red" StrokeThickness="20" >
<Rectangle.Fill>
<VisualBrush TileMode="None" Stretch="UniformToFill" Visual="{Binding ElementName=MyWindow, Path=Stuff}">
<!--<VisualBrush.Visual>
<MediaElement Source="MovingImages_2017-03-10-05-02-22.wmv" LoadedBehavior="Play" />
</VisualBrush.Visual>-->
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Window>
I have tried the following property as a visual and a media element.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WpfApp1
{
public partial class MainWindow : Window
{
public Visual Stuff { get; set; }
public MainWindow()
{
InitializeComponent();
MediaElement me = new MediaElement();
me.Source = new Uri("MovingImages_2017-03-10-05-02-22.wmv", UriKind.Relative);
me.LoadedBehavior = MediaState.Play;
this.Stuff = (Visual) me;
}
}
}
Edit 3. I have turned up binding errors and it is being bound. It turns up in the Live Visual Tree / Live property Explorer. It just does not show up.
Does anyone know why?