Is it possible to create/have a non-modal .net OpenFileDialog I have a UI element in the main dialog which always need to be available for the user to press.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
No, OpenFileDialog and SaveFileDialog are both derived from FileDialog, which is inherently modal, so (as far as I know) there's no way of creating a non-modal version of either of them.
It is an old post but I spend 2 days reaching the result I want to present here ( with "context" and complete but simplified code ) @Joshua 's answer worked for me ( at last when I put true to .ConfigureAwait(true), see first code sample). Maybe I was able to write less lines based on the long article of MSDN Threading Model that I still need to read once again.
My context is WPF ( basic MVVM ) and I must choose a file in order to write some .CSV backup ( of a datagrid ). I need that the (member) function
ChooseFileFromExtension()
be asynchronous with a non-blocking FileDialogand the code for MyFileDialog class
The
fetcher.BeginInvoke()
launches (asynchronously) theSaveFileDialog
ShowDialog()
in another thread so that the main UI Thread / Window (...++) are neither blocked nor disabled as they would have been with a simple direct call toShowDialog()
.TaskCompletionSource<string> tcs
is not an WPF UI Object so its access by another "single" thread is OK.It is still a field that I need to study further. I feel there is no "ultimate" documentation/book on the subject ( maybe should have a second look to books like the one from Stephen Cleary again). This code should be improved at least with topic covered on c-sharp-asynchronous-call-without-endinvoke
It works with the FileDialog of namespace Microsoft.Win32
You can create a thread and have the thread host the OpenFileDialog. Example code is lacking any kind of synchronization but it works.
With this code you could add something to fire an event in your UI thread (be careful with invoking!) to know when they're done. You can access the result of the dialog by
from your UI thread.
I know I am a little late but you may create a new form, borderless, transparent or outside the display bounds and show the file dialog modding that window.