WPF SaveFileDialog DefaultExt忽略了吗? [英] WPF SaveFileDialog DefaultExt ignored?
问题描述
var dlg = new SaveFileDialog();
dlg.FileName = "graph";
dlg.DefaultExt = ".bmp";
dlg.Filter = "PNG|*.png|DOT|*.dot|Windows Bitmap Format|*.bmp|GIF|*.gif|JPEG|*.jpg|PDF|*.pdf|Scalable Vector Graphics|*.svg|Tag Image File Format|*.tiff";
扩展名始终默认为 .png
。如果有 Filter
,似乎 DefaultExt
被忽略了;那么它只是默认为列表中的第一个选项。
The extension always defaults to .png
. It seems the DefaultExt
is ignored if there is a Filter
; then it just defaults to the first option in the list.
有没有一种方法可以强迫它实际上遵守默认扩展名?
Is there a way to force it to actually respect the default ext?
推荐答案
我为时已晚,但是巧合的是,我在查看此问题。
I'm a few years too late, but coincidentally, I found a solution to the problem while looking at the code from this question.
他在那里指定了不带的扩展名。
。然后,我查看了 Microsoft文档。在示例中,还指定了 DefaultExt
,而没有。
。
There he specified the extension without a .
. I then looked into the microsoft documentation. In the example the DefaultExt
was also specified without a .
.
如果 DefaultExt
用指定。
, FileDialog
将自动选择
DefaultExt
应该设置为不带的扩展名。
。
意味着在您的示例 dlg.DefaultExt = .bmp; 中,您需要更改
。bmp
到 bmp
...
DefaultExt
should be set to the extension without a .
.
Meaning that in your example dlg.DefaultExt = ".bmp";
you need to change ".bmp"
to "bmp"
...
这篇关于WPF SaveFileDialog DefaultExt忽略了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!