Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Windows.Forms and Windows.Input namespace conflicts

Back to Forum: Tech Off
  • User profile image
    fawad.khan

    My app classes are written using Slimdx and will interop to wpf and as such for testing purposes and to save time, I would like to use the event handlers from Windows.Forms namespace than the Window.Input which is written for WPF. When using Windows.Forms, we can't just typecast input event handlers from another namespace e.g. Windows.Input.  Possible solutions I can think of are add another name space or hard code the windows.forms namespace where needed. The latter looks lot cleaner and the winforms code will never make it to production since it is only for testing purposes.  My question is, are there better patterns/practices to resolving namespace conflicts when developing interop apps ?

  • User profile image
    W3bbo

    Just use namespace aliases.

     

    Rather than doing:

     

    using System.Windows.Input;

    using System.Windows.Forms;

     

    do this:

     

    using system.Windows.Input;

    using Swf = System.Windows.Forms;

     

    that way the namespaces don't collide, and if you want to use a WinForms class just prepend it with "Swf."

     

    eg:

     

    Button b = new Button(); // this is a WPF button

    Swf.Button = new Swf.Button(); // this is a WinForms button

  • User profile image
    vesuvius

    W3bbo said:

    Just use namespace aliases.

     

    Rather than doing:

     

    using System.Windows.Input;

    using System.Windows.Forms;

     

    do this:

     

    using system.Windows.Input;

    using Swf = System.Windows.Forms;

     

    that way the namespaces don't collide, and if you want to use a WinForms class just prepend it with "Swf."

     

    eg:

     

    Button b = new Button(); // this is a WPF button

    Swf.Button = new Swf.Button(); // this is a WinForms button

    or you can use type inference in the method and just

     

    var button = new System.Windows.Forms.Button()

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.