[英]OpenFileDialog.ShowDialog() throws an exception?
我試圖從我的WPF視圖模型命令之一顯示一個對話框,但是當我調用ShowDialog()
它拋出System.ArgumentException
,我想知道是否有人可以給我提示為什么?
這是我的代碼:
Public ReadOnly Property OpenParser As ICommand
Get
Return New RelayCommand(Sub(param As Object) OpenParserExecute(DirectCast(param, Frame)))
End Get
End Property
Public Sub OpenParserExecute(ByVal mFrame As Frame)
SaveParserExecute()
Dim mOpenDialog As OpenFileDialog = OpenDialog
If mOpenDialog.ShowDialog() Then ' Lines the throws the exception
CurrentParser = New ParserEditorModel(mOpenDialog.FileName)
mFrame.Navigate(New ParserEditor(CurrentParser))
End If
End Sub
根據要求的StackTrace:
at MS.Internal.Interop.HRESULT.ThrowIfFailed(String message)
at MS.Internal.AppModel.ShellUtil.GetShellItemForPath(String path)
at Microsoft.Win32.FileDialog.PrepareVistaDialog(IFileDialog dialog)
at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner)
at Microsoft.Win32.FileDialog.RunDialog(IntPtr hwndOwner)
at Microsoft.Win32.CommonDialog.ShowDialog()
at WinTransform.GUI.MainWindowModel.OpenParserExecute(Frame mFrame) in C:\Users\Alex\Desktop\MEDLI\branches\WinTransform\GUI\ViewModels\MainWindowModel.vb:line 38
因為ShowDialog()
本身返回Nullable(Of Boolean)
並且If
語句期望使用非Nullable Boolean
。
您必須將對話框的返回值轉換為Boolean
,如果為True
,則可以通過對話框的Filename
屬性檢索所選文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.