日期:2014-05-20 浏览次数:21394 次
[MarkupExtensionReturnType(typeof(System.Windows.Media.Imaging.BitmapSource))]
[ContentProperty("Key")]
public class ImageSource : MarkupExtension
{
public ImageSource()
: base()
{
}
public ImageSource(string key)
: base()
{
Key = key;
}
public string Key
{
get;
set;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(string.Format(@"{0}/{1}", Environment.CurrentDirectory, Key));
bi.EndInit();
bi.Freeze();
return bi;
}
}