title: Attach Image/ImageBrush from code behind
body: <p>I'm trying to add an Image as the background of a UserControl. Depending on the value of a variable I need to change that background but whatever the path or Uri format I use, the background does not change.</p>
  
  <p>I've seen lots of questions here in stackoverflow but none fixes my single problem.
  I let the code below:</p>
  
  <pre><code>            if (callback.liveUvis.ContainsUVI(uvi))
              {
                  this.Status.Text = "LIVE";
  
  
                  ImageBrush imgB = new ImageBrush();
                  BitmapImage btpImg = new BitmapImage();                    
                  btpImg.UriSource = new Uri(@"///IMG///Live///bck_frame_info_video_live.png", UriKind.Relative);
                  //imgB.ImageSource = new BitmapImage(new Uri("~/IMG/Live/bck_frame_info_video_live.png", UriKind.RelativeOrAbsolute));
                  //imgB.ImageSource = new BitmapImage(new Uri("ms-appx:///IMG/Live/bck_frame_info_video_live.png"));
                  imgB.ImageSource = btpImg;
                  this.Background = imgB;
              }
  </code></pre>
  
  <p>I'm facing the same problem when trying to attach an image... I guess it's up to the Uri format also, but I let the code too just in case :)</p>
  
  <pre><code>    private void setIcon_Desc(string dd)
      {
          try
          {
              Image img = new Image();
              img.Source = new BitmapImage(new Uri(this.BaseUri, "IMG/pictos_small/white/160dpi/" + dd + ".png"));
              img.Stretch = Stretch.None;
              this.Icon = img;
              this.Sport.Text = callback.disc.getDescription(dd).ToUpper();
          }
          catch(Exception ex)
          {
              callback.exception.writeExceptions(ex);
          }
  
      }
  </code></pre>
  
  <p>Thanks in advance!</p>