0
我的形象結合不斷拋出此錯誤:的IValueConverter是應該凍結跨線程安全的圖像結合工作不
Must create DependencySource on same Thread as the DependencyObject.
我寫了一個IValueConverter
,我認爲會解決,但似乎事實並非如此。
public class FrozenImage : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ImageSource image = value as ImageSource;
if (image != null)
{
if (image.Dispatcher != null)
{
if (image.Dispatcher.CheckAccess())
{
ImageSource returnImage = new BitmapImage();
returnImage = image;
returnImage.Freeze();
return returnImage;
} else return image.Dispatcher.Invoke(() => Convert(value, targetType, parameter, culture));
} else return image;
} else return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
我錯過了什麼,或者這是不可能的嗎?
也試過,因爲調度員應不需要的簡化版本,這有同樣的錯誤,以及:
public class FrozenImage : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ImageSource image = value as ImageSource;
if (image != null)
{
ImageSource returnImage = image.Clone();
returnImage.Freeze();
return returnImage;
} else return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}