WPF中的Image的Source赋值

xaml:<image Source="/LibraryName;component/Images/1.png"  x:Name="myImage">

code:myImage.Source = new BitmapImage(new Uri("/LibraryName;component/Images/1.png", UriKind.Relative));

  • /LibraryName是Image所在的Assembly的名字,前面的"/"是必须的。
  • ";component/"是Assembly名字和在此Assembly下具体路径之间的分隔符,必须要有。
  • "Images/1.png" 就是所在Assembly中的路径啦。

 

posted @ 2011-11-20 12:49  therockthe  阅读(808)  评论(0)    收藏  举报