I decided to port my WinForm project to WPF but I encounter a problem: My software has a user space. Normally, an image is selected via OpenFileDialog, this image is both stored and used by the control "Image" (roundPB in the code). But, my WinForm code does not work in WPF because the properties are not the same for a PictureBox for a "Image". Here is my current nonfunctional code :
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
Absolutely nothing works, neither roundPB (which is not showing the picture) nor the save, but no error message is returned. Can you enlighten me? Thank you!