title: XAML bind BitmapImage ViewModel property
body: <p>I have problem with update listbox from view model class. I use Caliburn Micro framework. My scenario is here:</p>
  <p>I bind property of type bindableCollection on listbox:</p>
  <p><strong>Code from view model:</strong></p>
  <pre><code>private BindableCollection&lt;UserInfo&gt; _friends;
  
  public BindableCollection&lt;UserInfo&gt; Friends
  {
      get { return _friends; }
      set
      {
          _friends= value;
          NotifyOfPropertyChange(()=&gt;Friends);
      }
  }
  </code></pre>
  <p>In view model I create a fake service method which return new fresh data as List and with this data I update a property Friends which is bind on listbox.</p>
  <p>I call fake service method in dispatcher timer tick event every 3 seconds.</p>
  <pre><code> private static UserInfo FakeUser()
          {
              var user = new UserInfo
              {
                  Age = &quot;16&quot;,
                  Emphasis = true,
                  IdUser = &quot;11542&quot;,
                  IsBlocked = false,
                  IsFriend = true,
                  LocationInfo = new Location
                  {
                      CityName = &quot;TN&quot;,
                      IdCity = 123456,
                      IdRegion = 1246,
                      RegionName = &quot;TN&quot;,
                  },
                  StatusInfo = new Status
                  {
                      IdChat = 12,
                      IsLogged = true,
                      LastLogin = &quot;153151&quot;,
                      IsChating = true,
                      RoomName = &quot;Car&quot;,
                  },
                  ProjectStatusInfo = new ProjectStatus(),
                  IsIamFriend = true,
                  PlusInfo = new Plus(),
                  ProfilePhoto = new BitmapImage(new Uri(&quot;http://pokec.azet.sk/vanes90?i9=1f104a294997&quot;, UriKind.RelativeOrAbsolute))
              };    
              return user;
          }
  
          private static IEnumerable&lt;UserInfo&gt; GetFakeFriends()
          {
              var list = new List&lt;UserInfo&gt;();
  
              for (int i = 0; i &lt; 20; i++)
              {
                  list.Add(FakeUser());
              }
  
              return list;
          }
  
          private void DispatcherTimer_Tick(object sender, EventArgs eventArgs)
          {
              if (_isExecuting)
                  return;
              _isExecuting = true;
              new System.Threading.Tasks.Task(() =&gt;
              {
                  var freshFriends = GetFakeFriends();
  
                  Execute.OnUIThread((System.Action)(() =&gt;
                  {
                      Friends.Clear();
                      foreach (var freshFriend in freshFriends)
                      {
                          Friends.Add(freshFriend);
  
                      }
                  }));
              }).Start();
  
              _isExecuting = false;
          }
  
      }
  </code></pre>
  <p>If I don't apply any style on listbox, it works good.</p>
  <p><strong>View:</strong></p>
  <pre><code>&lt;Grid&gt;
      &lt;ListBox Name=&quot;Friends&quot;
               Grid.Row=&quot;2&quot; 
               Margin=&quot;4,4,4,4&quot;&gt;
      &lt;/ListBox&gt;
  &lt;/Grid&gt;
  </code></pre>
  <p>If I apply some style in which I bind property ProfilePhoto (typeof BitmapeImage) from UserInfo on listbox.</p>
  <p>Style is here:</p>
  <pre><code>        &lt;Style x:Key=&quot;friendsListStyle&quot; TargetType=&quot;{x:Type ListBox}&quot;&gt;
              &lt;Setter Property=&quot;ItemTemplate&quot;&gt;
                  &lt;Setter.Value&gt;
                      &lt;DataTemplate&gt;
                          &lt;Grid Name=&quot;RootLayout&quot;&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width=&quot;0.3*&quot;&gt;&lt;/ColumnDefinition&gt;
                                  &lt;ColumnDefinition Width=&quot;*&quot;&gt;&lt;/ColumnDefinition&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition Height=&quot;60&quot;&gt;&lt;/RowDefinition&gt;
                              &lt;/Grid.RowDefinitions&gt;
                              &lt;Image Margin=&quot;4,4,4,2&quot; Source=&quot;{Binding Path=ProfilePhoto}&quot; Grid.Column=&quot;0&quot;/&gt;
                          &lt;/Grid&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  </code></pre>
  <p>I get this error:</p>
  <pre><code>Must create DependencySource on same Thread as the DependencyObject.
  
     at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri)
     at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
     at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
     at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
     at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
     at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
     at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
     at System.Windows.FrameworkElement.ApplyTemplate()
     at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
     at System.Windows.UIElement.Measure(Size availableSize)
     at System.Windows.Controls.Border.MeasureOverride(Size constraint)
  </code></pre>
  <p>If I make another style on listbox / listbox item, in which I bind only string or bool properties it works good.</p>
  <p>I have problem only if bind bitmapImage property.</p>
  <p>BitmapImage property is init as:</p>
  <pre><code>ProfilePhoto = new BitmapImage(new Uri(&quot;http://pokec.azet.sk/vanes90?i9=1f104a294997&quot;, UriKind.RelativeOrAbsolute))
  </code></pre>
  <p>URI is url of picture or path to the file.</p>
  <p>What is wrong? Thank for help and advice.</p>
  <p>Style is good, it work only if I don't refresh data with method call in another thread.</p>