0

I have border, 2 buttons and 2 jpg files.

This is code of my first button:

private void Button1_Click(object sender, RoutedEventArgs e)
{
    Uri uri = new Uri(@"C:\Users\abc\Documents\t1.jpg", UriKind.Relative);
    BitmapImage bi = new BitmapImage();
    bi.BeginInit();
    bi.CacheOption = BitmapCacheOption.OnLoad; 
    bi.UriSource = uri;
    bi.EndInit();
    ImageBrush ib = new ImageBrush(bi)
    {
        Stretch = Stretch.UniformToFill,
        AlignmentX = AlignmentX.Center,
        AlignmentY = AlignmentY.Center
    };
    myBorder.Background = ib;
}

This is code of my second button:

private void Button2_Click(object sender, RoutedEventArgs e)
{
    File.Copy(@"C:\Users\abc\Documents\t2.jpg", @"C:\Users\abc\Documents\t1.jpg", true);
}

What I am doing:

  1. Initial state:

enter image description here

  1. Click on button 1 (set): image t1.jpg is set as background of myBorder. That is OK.

enter image description here

  1. Click on button 2 (change file): content of file t1.jpg is replaced with content of file t2.jpg, names remain unchanged.

  2. Click on button 1 (set) again: now myBorder should have different background, because content of file t1.jpg has been replaced with content of file t2. jpg. But nothing happened! Why?

Gabriel
  • 377
  • 1
  • 3
  • 15
  • I notice that the second parameter of your `File.Copy` call does not have a '@' symbol, [In this MSDN page](https://msdn.microsoft.com/en-us/library/9706cfs5(v=vs.110).aspx) I notice the example has both paths use the '@' symbol. Could this be useful? – Jack Dec 15 '17 at 09:50
  • As a note, `C:\Users\abc\Documents\t1.jpg` is not a relative URI. Better don't set `UriKind` at all. It is hardly ever necessary. – Clemens Dec 15 '17 at 09:55

0 Answers0