【发布时间】:2013-12-28 13:31:41
【问题描述】:
我有一个按钮 b3 和一个名为 pictureBox1 的图像。我正在使用 WPF,但是我使用的是 winforms openFileDialog 而不是 WPF 附带的:
下面是我放在按钮点击事件中的代码:
private void b3_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog openDialogIcon = new System.Windows.Forms.OpenFileDialog();
if (openDialogIcon.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
Image i = new Image();
BitmapImage src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri(openDialogIcon.FileName, UriKind.Absolute);
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
i.Source = src;
i.Stretch = Stretch.Uniform;
//int q = src.PixelHeight; // Image loads here
}
}
当我单击按钮并选择一个图标时。该图标未出现在pictureBox1 中。
谁能解释一下为什么上面的代码没有显示图片框内的图标?
【问题讨论】:
-
我看不到你在哪里分配了一些东西给图片框1...
-
是的。这就是问题所在。抱歉,在发布此问题之前,我不得不进一步研究代码。