[IronPython] VideoBrush with IronPython and Silverlight

Michael Foord fuzzyman at voidspace.org.uk
Sat May 24 23:11:11 CEST 2008


Hello all,

I've been experimenting with using the VideoBrush from IronPython and 
Silverlight. It works fine from XAML, but the following code shows nothing:


from System.Windows import Application
from System.Windows.Controls import Canvas

#canv = Canvas()
#Application.Current.LoadRootVisual(canv, "app.xaml")

from System.Windows.Controls import TextBlock, MediaElement
from System import Uri, UriKind
from System.Windows.Media import VideoBrush, Stretch

root = Canvas()
video = MediaElement() 
source = Uri('../SomeVideo.wmv', UriKind.Relative)
video.Source = source
video.Opacity = 0.0

brush = VideoBrush()
brush.Stretch = Stretch.UniformToFill
brush.SetSource(video)

t = TextBlock()
t.Text = 'Video'
t.FontSize = 120
t.Foreground = brush

root.Children.Add(t)

Application.Current.RootVisual = root


The XAML that works is:

<Canvas x:Class="System.Windows.Controls.Canvas"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <MediaElement
      x:Name="videoMediaElement"
      Source="../SomeVideo.wmv" IsMuted="True"
      Opacity="0.0" IsHitTestVisible="False" />
     
    <TextBlock Canvas.Left="5" Canvas.Top="30" 
      FontFamily="Verdana" FontSize="120"
      FontWeight="Bold" TextWrapping="Wrap"
      Text="Video">
     
        <!-- Paint the text with video. -->
        <TextBlock.Foreground>
          <VideoBrush SourceName="videoMediaElement" 
Stretch="UniformToFill" />
        </TextBlock.Foreground>
    </TextBlock>

</Canvas>

Can anyone see what I'm doing wrong? (Or is this another beta bug.)

Thanks

Michael Foord
http://www.ironpythoninaction.com/



More information about the Ironpython-users mailing list