【发布时间】:2011-08-11 07:15:31
【问题描述】:
从一些例子来看,我认为我这样做是正确的,但它不起作用,所以我想在这里查看一下。我正在绑定我的图像源,但图像不存在。如果我取消绑定并将图像源设置为下面方法中使用的路径,它就可以正常工作。
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" />
【问题讨论】: