【发布时间】:2015-04-15 23:48:51
【问题描述】:
我决定将我的 WinForm 项目移植到 WPF,但遇到了一个问题: 我的软件有一个用户空间。通常,通过 OpenFileDialog 选择图像,该图像由控件“Image”(代码中的roundPB)存储和使用。但是,我的 WinForm 代码在 WPF 中不起作用,因为“图像”的 PictureBox 的属性不同。 这是我当前的非功能代码:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim OpenFileDialog2 As New Microsoft.Win32.OpenFileDialog()
Dim ImagePath As String = Nothing
If OpenFileDialog2.ShowDialog() = vbOK Then
ImagePath = OpenFileDialog2.FileName
My.Computer.FileSystem.CopyFile(ImagePath, ImageRep & System.Environment.GetEnvironmentVariable("ProgramFiles") & "\MTS\profpic.png", overwrite:=True)
Else : Exit Sub : End If
If roundPB IsNot Nothing Then roundPB.Source.Freeze()
roundPB.Source = New BitmapImage(New Uri(ImagePath, UriKind.Relative))
End Sub
Private Sub MetroWindow_Loaded(sender As Object, e As RoutedEventArgs)
If My.Computer.FileSystem.FileExists(System.Environment.GetEnvironmentVariable("ProgramFiles") & "\MTS\profpic.png") Then
Dim ImagePath As String = System.Environment.GetEnvironmentVariable("ProgramFiles") & "\MTS\profpic.png"
roundPB.Source = New BitmapImage(New Uri(ImagePath, UriKind.Relative))
roundPB.Source.Freeze()
End If
End Sub
绝对没有任何效果,roundPB(没有显示图片)和保存都没有,但没有返回错误消息。 你能启发我吗? 谢谢!
【问题讨论】:
-
没有
Handles子句。你确定这些事件正在触发吗? -
Else : Exit Sub : End If这种格式是反人类罪。 -
是的,当我单击按钮时,会显示 openfiledialog,但当我选择图片时没有任何反应。 (对不起我的罪行,我不会杀人:p)