C# IMultiValueConverter中提到DependencyProperty的异常
我尝试在列表框中获取图像,为iMultiValueConverter提供路径,在后台线程中执行此操作:C# IMultiValueConverter中提到DependencyProperty的异常,c#,wpf,C#,Wpf,我尝试在列表框中获取图像,为iMultiValueConverter提供路径,在后台线程中执行此操作: <Image> <Image.Source> <MultiBinding Converter="{StaticResource UriToBitmapConverter}"> <MultiBinding.Bindings> <Binding RelativeSource="{RelativeSourc
<Image>
<Image.Source>
<MultiBinding Converter="{StaticResource UriToBitmapConverter}">
<MultiBinding.Bindings>
<Binding RelativeSource="{RelativeSource Self}" />
<Binding Source="{Binding ImagePath}" />
</MultiBinding.Bindings>
</MultiBinding>
</Image.Source>
</Image>
我得到:
类型的未处理异常
中出现“System.Windows.Markup.XamlParseException”
PresentationFramework.dll
其他信息:无法在“源”上设置“绑定”
类型为“Binding”的属性。只能在服务器上设置“绑定”
DependencyObject的DependencyProperty
你能告诉我我做错了什么吗 您正在尝试在绑定中设置绑定:
。您是否尝试设置
?如果我这样做,我得到:错误“Binding”类型的“Path”属性上无法设置“Binding”,因此您将
替换为
,现在您得到两个错误?我通过编译得到:错误“Binding”类型的“Path”属性上无法设置“Binding”ImagePath是observablecollection中的类变量
public class UriToBitmapConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values[1] == null) return null;
BitmapImage BI= null;
Image image = values[0] as Image;
string mypath = values[1] as string;
FileStream fileStream = new FileStream(mypath, FileMode.Open, FileAccess.Read);
ThreadPool.QueueUserWorkItem((WaitCallback)delegate
{
image.Dispatcher.Invoke(DispatcherPriority.Normal,
(ThreadStart)delegate
{
BI= new BitmapImage();
BI.BeginInit();
BI.StreamSource = fileStream;
BI.EndInit();
image.Source = BI;
});
});
return BI;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}