在资源文件中定义转换器,把字符串转换为BitmapImage类型
<Window.Resources>
<local:StringToImageSourceConverter x:Key="MyImageConverter"></local:StringToImageSourceConverter>
</Window.Resources>
<Image Source="{Binding Path=ImgSource, ElementName=this, Converter={StaticResource MyImageConverter}}" Grid.Column="1" Width="290" Height="135" Stretch="Fill"></Image>
实现INotifyPropertyChanged接口,程序运行过程中,绑定的图片url变化后,界面上的图片即时变化。
private string _imageSource = null;
public string ImgSource
{
get
{
return _imageSource;
}
set
{
if (value != _imageSource)
{
_imageSource &