WinForm Considerations

  • Updated

Embedding the InRule WPF controls in a WinForm application works the same is it does with WPF.  This includes the initialization of the ControlFactory, loading the controls and saving changes.  There are, however, a couple considerations to be aware of.

ElementHost control

In order to host a WPF control in a WinForm application, the ElementHost control must be used.  This control was built for this exact purpose and is not specific to InRule.

// Get the business language editor and load into ElementHost control
elementHost.Child = _controlFactory.GetControl(langRule);

WPF Application Object

WPF controls that have popups require an instance of the WPF Application Object.  In a WPF application, this is automatically created.  This is not the case in a WinForm application.  For this reason, this object must be created manually.  The Application also must be set to remain open until it is shut down through code, otherwise it will shut automatically when the WinForm applications determines it is no longer needed.  The following code will open the Application object in a WinForm and keep it open until it is closed.  Shutting down the Application object when the WinForm closes is the recommended approach.

// Create appliication object
System.Windows.Application app = new System.Windows.Application();

// Set shutdown mode to explicit
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;

// Create a delegate that will close the app object when the WinForm closes
Closed += delegate { app.Shutdown(); };

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.