原文:WPF中Image控件的Source属性 imgBook 是一个Image控件,在后台代码中我想给它指定Source的属性.我先如下方式进行: Uri uri = new Uri(strImagePath, UriKind.RelativeOrAbsolute); imgBook.Source = new BitmapImage(uri); strImagePath是图片的绝对路径. 在另一处代码中我想把strImagePath指定的图片删掉,操作如下: if (System.IO.Fil…
工作上需要从给定的接口获取数据,然后显示在界面的编辑框中,以往肯定会一个一个的去赋值,但这样太麻烦而且效率很低,不利于维护,于是想到了数据绑定这一方法,数据绑定主要利用INotifyPropertyChanged这一接口去监听属性是否发生改变.下面是我写的一个demo,主要是利用控件的DataContext属性绑定数据 1.数据源 using System; using System.Collections.Generic; using System.ComponentModel; using…
1.直接关联到文件,关联后不能删除此图片,因为图片正在使用. imageEditImage.Source = new BitmapImage(new Uri(strImagePath, UriKind.Absolute));//strImagePath 就绝对路径 2.转成二进制,与图片原文件脱离 var img = new BitmapImage(); img.BeginInit(); img.StreamSource = new MemoryStream(File.ReadAllBytes(…