日期:2014-05-17 浏览次数:21403 次
private void Button_Click(object sender, RoutedEventArgs e) { //最好使用WPF原生OpenFileDialog Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Title = "选择文件"; openFileDialog.Filter = "jpg|*.jpg|jpeg|*.jpeg"; openFileDialog.FileName = string.Empty; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.DefaultExt = "jpg"; bool? result = openFileDialog.ShowDialog(); if (result !=true) { return; } string fileName = openFileDialog.FileName; this.textBox1.Text = fileName; BitmapImage image = new BitmapImage(new Uri(fileName)); image1.Source = image; }