OpenFileDialog.ShowDialog()抛出一个异常? [英] OpenFileDialog.ShowDialog() throws an exception?

查看:842
本文介绍了OpenFileDialog.ShowDialog()抛出一个异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的WPF视图模型中的一个显示一个对话框的命令时,我称之为的ShowDialog(),它抛出一个 System.ArgumentException ,我想知道如果任何人都可以给我一个提示,为什么?

I am trying to show a dialog from one of my WPF view model commands however when i call ShowDialog() it throws a System.ArgumentException, I was wondering if anyone could give me a hint as to why?

下面是我的code:

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

堆栈跟踪的要求: 在MS.Internal.Interop.HRESULT.ThrowIfFailed(字符串消息)在MS.Internal.AppModel.ShellUtil.GetShellItemForPath(字符串路径),在Microsoft.Win32.FileDialog。prepareVistaDialog(IFileDialog对话框)在Microsoft.Win32.FileDialog .RunVistaDialog(IntPtr的hwndOwner)在Microsoft.Win32.FileDialog.RunDialog(IntPtr的hwndOwner)在Microsoft.Win32.CommonDialog.ShowDialog()在WinTransform.GUI.MainWindowModel.OpenParserExecute(帧mFrame)在C:\用户\亚历克斯\桌面\ MEDLI \分支机构\ WinTransform \ GUI \的ViewModels \ MainWindowModel.vb:38行

StackTrace as requested: " 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()本身返回可空(布尔)和您的如果语句期待一个非空的布尔

Because ShowDialog() itself returns a Nullable(Of Boolean) and your If statement is expecting a non-Nullable Boolean.

您将不得不在对话框的返回值转换为布尔,如果它 retreive选定的文件通过你的对话框的文件名属性。

You'll have to cast the dialog's return value to a Boolean and if it's True retreive the selected file through your dialog's Filename property.

<一个href="http://www.vbdotnetheaven.com/UploadFile/dbeniwal321/OpenFileDialogwpf08162009233449PM/OpenFileDialogwpf.aspx"相对=nofollow>为例。

这篇关于OpenFileDialog.ShowDialog()抛出一个异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆