Is it true, that wpf has no built in support to use the vista folder select dialog? (At least there is no such thing in the Microsoft.Win32 namespace with the other file dialogs.) If yes, why?
Im currently working my way around with reflection:
private static bool RunVistaDialog(OpenFileDialog openFileDialog, IntPtr hwndOwner) { Type typeOfd = typeof(FileDialog); MethodInfo mi = typeOfd.GetMethod("CreateVistaDialog", BindingFlags.Instance | BindingFlags.NonPublic); Type dialogType = mi.ReturnType; object dialog = mi.Invoke(openFileDialog, null); mi = typeOfd.GetMethod("PrepareVistaDialog", BindingFlags.Instance | BindingFlags.NonPublic); mi.Invoke(openFileDialog, new object[] { dialog }); mi = dialogType.GetMethod("GetOptions"); object fos = mi.Invoke(dialog, null); Type typeFOS = fos.GetType(); FieldInfo fi = typeFOS.GetField("PICKFOLDERS"); fos = (uint)fos | (uint)fi.GetValue(null); mi = dialogType.GetMethod("SetOptions"); mi.Invoke(dialog, new object[] { fos }); mi = dialogType.GetMethod("Show"); object hresult = mi.Invoke(dialog, new object[] { hwndOwner }); PropertyInfo pi = hresult.GetType().GetProperty("Succeeded"); bool succeeded = (bool)pi.GetValue(hresult, null); if (!succeeded) return false; mi = typeOfd.GetMethod("ProcessVistaFiles", BindingFlags.Instance | BindingFlags.NonPublic); string[] filenames = (string[])mi.Invoke(openFileDialog, new object[] { dialog }); fi = typeOfd.GetField("_fileNames", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(openFileDialog, filenames); return succeeded; }
This seems to work, but that raises the question, why this functionality is not provided by the api. The methods are obviously there...