从一些例子来看,我认为我这样做是正确的,但它没有用,所以我想在这里查看。我绑定了我的图像源,但图像不在那里。如果我带走了我的绑定并将Image源设置为下面方法中使用的路径,它就可以正常工作。
public Image myImage = new Image();
public void someMethod() {
BitmapImage biSource = new BitmapImage();
biSource.BeginInit();
biSource.CacheOption = BitmapCacheOption.OnLoad;
biSource.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
biSource.UriSource = new Uri(@"C:\Images\testimage.jpg");
biSource.DecodePixelWidth = 150;
biSource.EndInit();
myImage.Source = biSource;
}
xaml code
<Image Source="{Binding Path=myImage}" Width="150" Height="150" />
答案 0 :(得分:7)
您应该将Source
属性绑定到ImageSource
,而不是Image
。将biSource
公开为属性并绑定到它而不是myImage
答案 1 :(得分:5)
您尝试将Image
绑定到Image
的来源,但无法正常工作。您需要将BitmapImage
绑定到Image
的源。
此外,BitmapImage
需要作为公共财产公开。如果您不熟悉数据绑定,请阅读this overview on MSDN。
此外,您应该学习how to debug bindings。