选择图片并加载显示
private void shopPicButton_Click(object sender, RoutedEventArgs e) {//选择图片并加载显示 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "JPEG Files(*.jpg) | *.jpg | PNG Files(*.png) | *.png | BMP Files(*.bmp) | *.bmp | All files(*.*) | *.*"; openFileDialog.Title = "选择一个图片文件"; if (openFileDialog.ShowDialog()==true) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(openFileDialog.FileName); //bitmapImage.DecodePixelWidth = 200; bitmapImage.EndInit(); myImage.Source = bitmapImage; } } private void clearPicButton_Click(object sender, RoutedEventArgs e) {//清除图片 myImage.Source = null; }