java 文本框获取焦点 showopendialog冲突,OpenFileDialog.ShowDialog()抛出异常?

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?

Here is my 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

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

解决方案

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值