title: Drawing image into a Window and update it
body: <p>I have an unsafe class that generate a Bitmap which is converted to ToImageSource in order to draw into a Window. The Bitmap itself contains a sinusoidal text which is frequently updated and I want to it "move" from the left to the right (marquee style?). Anyway it works just fine in a WinForm but I'm stuck with the WPF Window.</p>
  
  <p>Here are some code samples:</p>
  
  <pre><code>public AboutWindow()
  {
      InheritanceBehavior = InheritanceBehavior.SkipAllNow;
      InitializeComponent();
      Initialize();
  }
  
  protected override void OnRender(DrawingContext drawingContext)
  {
      base.OnRender(drawingContext);
  
      drawingContext.DrawImage(bitmapRender.WindowBitmap, drawingArea);
  
      if (!worker.IsBusy) 
          worker.RunWorkerAsync(); // BackgroundWorker in charge of updating the bitmap
  }
  
  void DispatcherTimerRender_Tick(object sender, EventArgs e) =&gt; InvalidateVisual();
  </code></pre>
  
  <p>My issues are: there is nothing displayed on the Window and the DispatchedTimer that calls InvalidateVisual() leads to this exception: </p>
  
  <blockquote>
    <p>System.InvalidOperationException: 'Cannot use a DependencyObject that belongs to a different thread than its parent Freezable.'</p>
  </blockquote>
  
  <p>I have looked at other threads and I'm aware that WPF is a retained drawing system but I would love to achieve it anyway.</p>
  
  <p>Any suggestion about the "best" way to achieve this?</p>
  
  <p>Any useful explanation/link would be very much appreciated.</p>
  
  <p>[Edit] </p>
  
  <pre><code>&lt;Window x:Class="CustomerManagement.View.AboutWindow"
          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"
         mc:Ignorable="d" Height="450" WindowStartupLocation="CenterScreen" Width="800" ResizeMode="NoResize" AllowsTransparency="True" WindowStyle="None"&gt;
      &lt;Grid KeyDown="Grid_KeyDown"&gt;
          &lt;Image Width="800" Height="450" Source="{Binding 'Image'}" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>