Today, I would like to give a quick overview and an example of new ManagedHost control that has been introduced in AX 2012.
The ManagedHost is a Microsoft Dynamics AX control that hosts a .NET control on a form Actually, you can add and use Windows Presentation Foundation (WPF) or managed form controls. This was not available in DAX 2009.
The ManagedHost supports access to the properties, methods, and events of the specified .NET control. To provide access to these members of the .NET control, the ManagedHost uses the CLR interop feature of X++. [msdn]
Let me explain with a real quick example.
Create a new form and add a new ManagedHost control as shown below
From the control selectors, select System.Windows.Forms and Button control as shown below and click on Ok Button
Actually, I am trying to add a .NET button control and will invoke the events of the control from AX.
Then, Right click on the ManagedHost control and chose Events
From the list of events, select the click event and click on Add button as shown below
Once you do this, you will automatically find that in the ClassDeclaration the control object is created.
public class FormRun extends ObjectRun
Also, init() method will have the following code with the eventHandler.
You use the properties of the .NET control to configure that control or to obtain information from the control. To set a property value, assign a value to the set_<property name> property of the .NET control. To retrieve a value from a .NET control, use the get_<property name> property of the .NET control. [msdn]
I have added one line of code to set the button text as shown below
Init() method – code below
public void init()
_ManagedHost_Control = ManagedHost.control();
_ManagedHost_Control.add_Click(new ManagedEventHandler(this, ‘ManagedHost_Click’));
_ManagedHost_Control.set_Text("Open customer table");
When the button is clicked, ManagedHost_Click method gets triggered and I am just opening the customer table in the clicked event
void ManagedHost_Click(System.Object sender, System.EventArgs e)
If we open the events again, you will see that click event is mapped to AX X++ method “ManagedHost_Click” as shown below [just for your reference]
We are done, Now right click on the form and chose Open.
You will see that .NET Button control is on your form with text “Open customer table” a shown below
Click on the button and you should see the custTable opening in the TableBrowser.
You can try with other controls like Grid Views, progress bars, Calendar pickers or any other controls from the controller list, but I was unable to access some of the events/methods of .net controls in AX when I tried some [Chart control, Combo Box] .
hmm..Exploring more…will post soon.
For more details : http://msdn.microsoft.com/en-us/library/gg864879.aspx
Have a good weekend!