Honestly, the best, easiest, cleanest solution is to make another version of the Main
method which accepts System.Windows.Controls.Control
instead of System.Windows.Forms.Control
. They can even be overloaded (share the same name). The changes to this new version would probably be very few and simple.
However, assuming Main
is some huge, complicated method that would be a nightmare to even look at- or you don't have the source code anymore- and you really have to use the existing method, there is one other potential option:
Make a class that inherits from System.Windows.Forms.Control
which will act as a wrapper around a System.Windows.Controls.Control
. You can use new and/or override keywords to replace the existing properties in System.Windows.Forms.Control
and instead expose the equivalent properties of System.Windows.Controls.Control
.
To give a rushed example:
class WinformsControlWrapper : System.Windows.Forms.Control
{
protected System.Windows.Controls.Control WrappedControl;
public WinformsControlWrapper(System.Windows.Controls.Control wrappedControl)
{
WrappedControl = wrappedControl;
}
public new int Width
{
get { return (int)WrappedControl.Width; }
set { WrappedControl.Width = value; }
}
}
Of course there are numerous problems even with the above example: the fact that WPF uses double
and winforms uses int
, and the fact that WPF has both Width
and ActualWidth
to name a couple. But you should probably be able to write your class to work the way you need it to.
Again, making another version of Main
is a much simpler, cleaner and probably easier solution. But if you really can't the above tactic should work.