<Image x:Name="pageImg" Margin="-19,-1,37,19" Source="/img/1.png" Stretch="Uniform" />
Images屬性也設置爲Build Action = Resource
和複製Output Directory = Cope if newer
崩潰關於更改圖片來源財產
當按鈕獲得點擊應用程序崩潰:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
pageImg.Source = new BitmapImage(new Uri(@"/img/2.png"));
}
但是當我通過C:\Users\myuser\Desktop\2.png
代替/img/2.png
它工作得很好。
爲什麼會發生這種情況?
可能重複的[在後面的代碼更改圖像源 - Wpf](http://stackoverflow.com/questions/3787137/change-image-source-in-code-behind-wpf) –
@ J.H。感謝它很好地工作。 – Vlad