2011-06-21 75 views
0

私はWPFビューモデルのコマンドの1つからダイアログを表示しようとしていますが、ShowDialog()System.ArgumentExceptionをスローすると、なぜ誰かが私にヒントを与えることができるのだろうかと疑問に思っていましたか?要求されたようOpenFileDialog.ShowDialog()は例外をスローしますか?

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::自身がNullable(Of Boolean)とあなたのIf文がnull非許容Boolean期待しているが返されます

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 
+0

OpenDialogオブジェクトに問題があります。あなたが例外のStackTraceを投稿しない限り、それが何であるかを推測するのは難しいです。 –

+0

スタックトレースを追加しました。 –

+1

OpenDialog.InitialDirectoryプロパティに問題があります。 –

答えて

3

ShowDialog()ので

は、ここに私のコードです。

ダイアログの戻り値をBooleanにキャストし、Trueの場合はダイアログのFilenameプロパティで選択したファイルを取得する必要があります。

Example

関連する問題