title: WPF BitmapImage not displaying
body: <p>I have a WPF project which uses, as best I can, the MVVM pattern. I'm using Visual Studio 2010, and the language behind is C#.</p>
  
  <p>So I have a treeview. The treeview looks like this:</p>
  
  <pre><code>&lt;TreeView Grid.Column="0" Width="Auto" Background="Aquamarine" ItemsSource="{Binding Scenes}" SelectedItemChanged="TreeView_SelectedItemChanged"&gt;
          &lt;TreeView.DataContext&gt;
              &lt;viewModels:ScenesViewModel /&gt;
          &lt;/TreeView.DataContext&gt;
          &lt;TreeView.ItemTemplate&gt;
              &lt;HierarchicalDataTemplate ItemsSource="{Binding Characters}"&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="{Binding SceneName}"&gt;&lt;/TextBlock&gt;
  
                          &lt;Image Source="{StaticResource ImgWorld}" Margin="0,0,5,0" Width="32" Height="32"/&gt;
  
                  &lt;/StackPanel&gt;
                  &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
  
                              &lt;TextBlock Text="{Binding FirstName}"&gt;&lt;/TextBlock&gt;
                              &lt;Border BorderThickness="1" Background="RoyalBlue"&gt;
                                  &lt;Image Source="{Binding ImgIcon}" Margin="2"/&gt;
                              &lt;/Border&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/TreeView.ItemTemplate&gt;
      &lt;/TreeView&gt;
  </code></pre>
  
  <p>The point of contention is the Image, the source of which is bound to something called 'ImgIcon'. This is a property of a view model called 'CharacterViewModel'. For some reason I am getting nothing displayed where the image should be. </p>
  
  <p>The most obvious issue might be regarding the data context or whether the MVVM side of things is working. I am fairly sure it is, as there is a TextBlock next to the Image which is also bound to a property called 'FirstName'. This binding works fine.</p>
  
  <p>The two properties are, of course, in the view model, and can be seen here:</p>
  
  <pre><code>public String FirstName
      {
          get { return Character.FirstName; }
          set
          {
              if (Character.FirstName != value)
              {
                  Character.FirstName = value;
                  RaisePropertyChanged("FirstName");
              }
          }
      }
  
  private BitmapImage _imgIcon = null;
      public BitmapImage ImgIcon 
      { 
          get { return _imgIcon; }
          set 
          {
              _imgIcon = value;
              RaisePropertyChanged("ImgIcon");
          }
      } 
  </code></pre>
  
  <p>They are slightly different in that the latter does not wrap around a property in the Character class.</p>
  
  <p>So the next possible fault would be the loading of the image. This is accomplished by this method (which at the moment just has a test path for a known working file):</p>
  
  <pre><code>public bool LoadIcon()
      {
          if (ImgIcon == null)
          {
              Uri outUri;
  
              if (Uri.TryCreate(@"D:\Pictures\Icons\HCAria01.png", UriKind.Absolute, out outUri) )
              {
              }
  
  
              ImgIcon = new BitmapImage(outUri);
              return true;
          }
          else
              return false;
      }
  </code></pre>
  
  <p>I put a break point in at 'ImgIcon = new BitmapImage(outUri)' and you can see the relevant information here: <a href="https://imgur.com/a/t4avw" rel="nofollow noreferrer">picture</a>. It seems from this picture that the image has loaded successfully. </p>
  
  <p>I'm sure I'm missing something obvious, but I'm damned if I can say what it is. From my limited experience with WPF and XAML, it seems to be working okay, except for the lack of an image.</p>
  
  <p>Well, if you can offer any help that would be much appreciated.</p>
  
  <p><strong>Edit</strong>: a couple of clarifications. The DataContext for the Treeview is called ScenesViewModel. This holds a list of SceneViewModel, and that list is called 'Scenes'. Each SceneViewModel containst a list of CharacterViewModel, and that is called 'Characters'. <a href="https://imgur.com/a/BMjQG" rel="nofollow noreferrer">These two images</a> show the relevant part of those classes, so hopefully the hierarchy can be understood. For each CharacterViewModel, there should be an ImgIcon.</p>