C#探秘系列(十)WPF:打开文件选择器选择文件并保存
//此为点击按钮的监听事件,点击按钮弹出文件选择器
private void imageButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog();
dialog.Filter = ".jpg|*.jpg|.png|*.png|.jpeg|*.jpeg";
if (dialog.ShowDialog(this) == false) return;
_fileName = dialog.FileName;
//初始化图片
BitmapImage tempImage = new BitmapImage();
tempImage.BeginInit();
tempImage.UriSource = new Uri(_fileName, UriKind.RelativeOrAbsolute);
tempImage.EndInit();
//imageCavas为窗口中设置的Image控件
imageCavas.Source = tempImage;
}