Nic*_*lai 3 data-binding wpf asynchronous datagridview bitmapsource
我有一个问题,我的WPF应用程序.我正在尝试使用viewmodel中的image属性在我的gridview中对图像字段进行数据绑定.
<DataGridTemplateColumn Header="Image" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path=Image, IsAsync=True}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
如果我不使用IsAsync,这没问题.但是,我想做异步,因为它需要加载大量图像,并且需要从Web服务加载它们.
Image属性的代码是this,它只调用一个调用web服务的处理程序dll.
public BitmapSource Image
{
get { return image ?? (image = ImageHandler.GetDefaultImages(new[] {ItemNumber},160,160)[0].BitmapSource()); }
}
Run Code Online (Sandbox Code Playgroud)
但是,只要我添加了IsAsync = true,我就会在表单加载后得到以下异常:
The calling thread cannot access this object because a different thread owns it.
我是WPF的新手,我有点假设,当async设置为true时,它处理了线程本身.在数据绑定中是否需要以某种方式调用?如果是这样,我该怎么做呢?
| 归档时间: |
|
| 查看次数: |
1818 次 |
| 最近记录: |