I have a datagrid with a template column. The template has an image:
<Image HorizontalAlignment="Left" Name="ImageProduct" Stretch="None" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" Source="{Binding Path=ProductImage, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality"/>
The grid scrolls very slowly because the ProductImage lazilly loads a private bitmapimage object as the user scrolls the grid. I was thinking of using another thread to load the private variable (behind the ProductImage property). I'm getting into trouble with my code because of various reasons...one exception was I can only update UI on the STA thread and another was a dependency source can't be in a different thread than the dependency sink (?)
I can't think of a good way to do this. The code for the grid looks something like this with a failed attempt at the backgroundworker:
var productVMList = GetProducts();
_window.ReceivingBatchProductsGrid.ItemsSource = productVMList;
var setProductImageWorker = new BackgroundWorker();
setProductImageWorker.DoWork += setProductImageWorker_DoWork;
setProductImageWorker.RunWorkerAsync(productVMList);
And here is DoWork:
var products = (ObservableCollection)e.Argument;
foreach (var product in products)
{
product.SetProductImage();
}
Any thoughts?