I am trying to bind image source, the thing is that: I have a folder with a filesystemwatcher - each time a new image file is added to the folder - I'm getting the full path of the image and want to bind that to the source of the image control. So the images will change automatically in the GUI everytime a new TIFF file is added to the folder.
This is what I've done:
XAML:
<Window x:Class="WpfApplication2.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"
    xmlns:local="clr-namespace:WpfApplication2"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="414,159,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
        <Image x:Name="img1" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" RenderTransformOrigin="1.604,1.161" Source="{Binding ButtonImage}" />
    </Grid>
</Window>
MainWindow.xaml.cs
private ImageSource b;
public  ImageSource ButtonImage
{
    get { return b; }
    set
    {
        b = value;
    }
}
private void button_Click(object sender, RoutedEventArgs e)
{
    ButtonImage = new BitmapImage(new Uri(@"C:\Users\x\Desktop\1.tif"));
    watch();
}
private void watch()
{
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = @"C:\Users\x\Desktop\ti";
    watcher.Created += new FileSystemEventHandler(OnChanged);
    watcher.EnableRaisingEvents = true;
    watcher.Filter = "*.tif";
}
private void OnChanged(object source, FileSystemEventArgs e)
{
    ButtonImage = new BitmapImage(new Uri(e.FullPath));
}
 
     
     
    