<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