title: DataBinding and Timer in WPF?
body: <p>I'm gonna write a code with DataBinding and a Timer to change an Image sequentially.<br />
  e.g: in each two seconds.</p>
  
  <p>below is my C# code : <br /></p>
  
  <pre><code>public class GenerateRandomImagePath
  {
      Random random = new Random((int)DateTime.Now.Ticks);
      readonly int MinInt;
      readonly int MaxInt;
      readonly string PrefixImagesName;
      readonly string ImageExtension;
  
      /// &lt;summary&gt;
      /// Used in data binding
      /// &lt;/summary&gt;
      public string ImageFullPath { get; set; }
  
      public GenerateRandomImagePath(string prefixName, string extension)
      {
          this.PrefixImagesName = prefixName;
          this.MinInt = 1;
          this.MaxInt = 100;
          this.ImageExtension = extension;
      }
  
      int RandomNumber()
      {
          return random.Next(this.MinInt, this.MaxInt);
      }
  
      public void GenerateNewRandomImagePath()
      {
          this.ImageFullPath = this.PrefixImagesName + RandomNumber() + this.ImageExtension;
      }
  }
  
  public partial class MainWindow : Window
  {
      GenerateRandomImagePath RandomImagePath;
      System.Timers.Timer timer = new System.Timers.Timer(2000);
  
      public MainWindow()
      {
          InitializeComponent();
          RandomImagePath = new GenerateRandomImagePath(@"C:\Users\MDS\Pictures\Nature 02\Nature ", @".jpg");
          timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
          timer.Enabled = true;
  
          this.DataContext = RandomImagePath;
          RandomImagePath.GenerateNewRandomImagePath();//this line works well
      }
  
      void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
      {
          RandomImagePath.GenerateNewRandomImagePath();
      }
  }
  </code></pre>
  
  <p>The XAML code : <br /></p>
  
  <pre><code>&lt;Window
      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:Class="sth.MainWindow"
      x:Name="Window"
      Title="MainWindow"
      Width="800" Height="600" mc:Ignorable="d"&gt;
  
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;Image Source="{Binding Path=ImageFullPath}" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>The code works just for first time! After that, the timer changes <b>ImageSource</b> but it doesn't effect on view!<br />
  Would you please guide me?</p>
  
  <p>Thanks</p>