我使用以下代码将图像绑定到Image Control(CustomerImage)。我通过创建新图像不断将新图像绑定到图像控件,下面的代码可以正常工作两到三次。之后,当我创建新图像时会抛出异常。以下是错误
类型'System.NullReferenceException'的未处理异常 发生在PresentationCore.dll中的附加信息:对象 引用未设置为对象的实例。
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
CustomerImage.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
ImageSourceConverter isc = new ImageSourceConverter();
CustomerImage.Source = (ImageSource)isc.ConvertFromString(e.FullPath);
}
));
}