ADObjectPickerShowDialog with WPF window

Jan 12, 2010 at 6:35 AM

I recently upgraded from 3.6.0.2 to 3.6.0.4. In the version 3.6.0.2 the following worked

 

WindowInteropHelper helper = new WindowInteropHelper(wpfWindow);
ADObject[] res = DirectoryServicesUtils.ADObjectPickerShowDialog(helper.Owner, true);

However in the 3.6.0.4 version, the WindowInteropHelper object no longer satisfies ADObjectPickerShowDialog.

How can I open the ADObjectPickerShowDialog from within a WPF window?

Thanks,

Joe Rich

Coordinator
Jan 12, 2010 at 8:57 AM

Hi,

DirectoryServicesUtils.ADObjectPickerShowDialog

was moved to xxx into the NetSqlAzMan.SnapIn.dll assembly (NetSqlAzMan.SnapIn.DirectoryServices. namespace).

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Jan 12, 2010 at 11:50 AM

Andea,

Yes, I know that you moved it to another namespace. However, that is not my question.

I am trying to use it in a WPF app. I am trying to provide the method its IWin32Window handle using a WindowInteropHelper ohject like this

WindowInteropHelper helper = new WindowInteropHelper(wpfWindow);

I then pass in helper.Owner as the IWin32Window parameter. While this worked in the old version, in the new it produces a compiler error:

Error 1258 The best overloaded method match for 'NetSqlAzMan.SnapIn.DirectoryServices.DirectoryServicesUtils.ADObjectPickerShowDialog(System.Windows.Forms.IWin32Window, bool)' has some invalid arguments C:\Documents and Settings\JRICH\Projects\Pipeyard\Core\Globals\clsAppGlobals.cs 1957 17 Core

Error 1259 Argument '1': cannot convert from 'System.IntPtr' to 'System.Windows.Forms.IWin32Window' C:\Documents and Settings\JRICH\Projects\Pipeyard\Core\Globals\clsAppGlobals.cs 1957 65 Core

What am I missing?

Thanks,

Joe Rich

  

 

 



 

 

Jan 12, 2010 at 12:25 PM

I have tried creating a wrapper class as follows

public class Wpf32Window : IWin32Window
    {
        public IntPtr Handle { get; private set; }

        public Wpf32Window(Window wpfWindow)
        {
            Handle = new WindowInteropHelper(wpfWindow).Handle;
        }
    }
I then pass this in as the IWin32Window param. But the compiler will not accept it.
Error 32 Argument '1': cannot convert from 'System.Windows.Interop.IWin32Window' to 'System.Windows.Forms.IWin32Window' 
C:\Documents and Settings\JRICH\Projects\Pipeyard\Core\Globals\clsAppGlobals.cs 1957 83 Core
Regards
Joe Rich
Jan 13, 2010 at 3:19 AM

Never mind...i figured it out. The following works

System.Windows.Forms.IWin32Window wpf32 = new Wpf32Window(orgfrm);
ADObject[] res = DirectoryServicesUtils.ADObjectPickerShowDialog(wpf32,false,true,false);
Where Wpf32Window is the following class
public class Wpf32Window : System.Windows.Forms.IWin32Window
    {
        public IntPtr Handle { get; private set; }

        public Wpf32Window(Window wpfWindow)
        {
            Handle = new WindowInteropHelper(wpfWindow).Handle;
        }
    }
Thanks,
Joe Rich
Coordinator
Jan 13, 2010 at 6:54 AM
Great Job !
Andrea.