All examples still use the Win32 namespace, but there is an alternative:
FileInfo file = new FileInfo("image.jpg"); var dialog = new System.Windows.Forms.SaveFileDialog(); dialog.FileName = file.Name; dialog.DefaultExt = file.Extension; dialog.Filter = string.Format("{0} images ({1})|*{1}|All files (*.*)|*.*", file.Extension.Substring(1).Capitalize(), file.Extension); dialog.InitialDirectory = file.DirectoryName; System.Windows.Forms.DialogResult result = dialog.ShowDialog(this.GetIWin32Window()); if (result == System.Windows.Forms.DialogResult.OK) { }
I use the extension method to get IWin32Window from visual control:
#region Get Win32 Handle from control public static System.Windows.Forms.IWin32Window GetIWin32Window(this System.Windows.Media.Visual visual) { var source = System.Windows.PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource; System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle); return win; } private class OldWindow : System.Windows.Forms.IWin32Window { private readonly System.IntPtr _handle; public OldWindow(System.IntPtr handle) { _handle = handle; } System.IntPtr System.Windows.Forms.IWin32Window.Handle { get { return _handle; } } }
Capitalize() also an extension method, but it is not worth mentioning that there are many examples of capitalization of the first line of a line.
Chuck Savage Jan 22 '14 at 19:59 2014-01-22 19:59
source share