WPF图像控制源

Dab*_*ddo 8 c# image wpf-controls

我试图重新创建一个非常简单的C#项目示例我是WPF,它是一个简单的图像查看器..来自山姆自学C#,我设法让打开文件对话框打开,但我如何设置图像路径到WPF中的image.source控件?

private void SearchBtn_Click(object sender, RoutedEventArgs e)
{
     Microsoft.Win32.OpenFileDialog openfile = new Microsoft.Win32.OpenFileDialog();
     openfile.DefaultExt = "*.jpg";
     openfile.Filter = "Image Files|*.jpg";
     Nullable<bool> result = openfile.ShowDialog();
     if (result == true)
     {
       //imagebox.Source = openfile.FileName;
     }
}
Run Code Online (Sandbox Code Playgroud)

Cha*_*lie 19

imagebox.Source = new BitmapImage(new Uri(openfile.FileName));
Run Code Online (Sandbox Code Playgroud)