Has anyone suceeded in using a WPF control in OEA using elementHost ? I've managed to get the ElementHost added to the form, but am now stuck at what to do
jmls wrote:
Has anyone suceeded in using a WPF control in OEA using elementHost ? I've managed to get the ElementHost added to the form, but am now stuck at what to do
The last time I tried this, the below is what I found out/ran into (from an email). I got things to work at runtime, IIRC, but struggled in OEA.
.Net has a control called ElementHost which can be dropped onto a form (it
needs to be added to the toolbox first). The WPF control needs to be
available to the project, in the form of a DLL or EXE, and can be parented
to the ElementHost. The cool thing is that at this point you can write ABL
code to interact with the WPF control. For instance, I was able to create an
event handler in ABL for the WPF control.
Issues:
(1) In Visual Studio, the ElementHost control has a SmartTag, which is
missing in OEA/VD. It's also a visual control in VS; in OEA/VD it's not, and
the developer needs to code everything themselves.
(2) Using an exe as a reference didn't work well - I could add it using the
tool, but it was decorated with the "I don't work" icon after restarting the
project. The Add Assembly References tool allows me to select EXEs. Now this
could just be not doing something right, but the exe I was using is the one
generated by Visual Studio, and so I'd expect others to run into this issue.
-- peter
The last time I tried this, the below is what I found out/ran into (from an email). I got things to work at runtime, IIRC, but struggled in OEA.
>> .Net has a control called ElementHost which can be dropped onto a form (it
>> needs to be added to the toolbox first). The WPF control needs to be
>> available to the project, in the form of a DLL or EXE, and can be parented
>>
This is similar to what we did: Created a XAML Window in a DLL project and referenced that in OEA. The actual embedding of the WindowContainer was done in ABL code.
Has anyone suceeded in using a WPF control in OEA using elementHost ? I've managed to get the ElementHost added to the form, but am now stuck at what to do
I've done the other way round: XAML Window with the WPF WinForms Container Control and embedded an ABL Window (in the one and only GUI client) in the WindowContainer in the WinForms Container.
must be something wrong with my ElementHost - dropped it onto the form
ok, but when I reload the form I get the dreaded "I sorry, I can't do
that Dave" response from OEA.
How did you get Element host into your form ?
Peter, do you have the steps required to do this ? I've struggled and cannot seem to get a stable config.
Thanks
If you want use WPF , use juste WPF form and MVVM pattern.
you create WPFForm and a dataContext Interface in visual studio and create Object business and ViewModel (implement DataContext interface).
your WPF form need a methode who assigne you Interface at WPF form DataContext.
After if you want call you WPF form , you call begins a invisible Form and when form finish to load , you call your WPF Form.
Don't forget to implement a close event for invisible Form.
All OE Object with interact with wpf form need to implement C# interface with a fonctionne you need.
I work with mecanics , it's work: Just few difficulte with ObservableCollection (you need create object inherits ObservableCollection with T you Type you want use).
Exemple :
Invisible form:
CLASS Sage.WPF.WPFShadowsForm INHERITS Form:
DEFINE PRIVATE VARIABLE components AS System.ComponentModel.IContainer NO-UNDO.
DEFINE PRIVATE VARIABLE pWPFform AS System.Windows.Window NO-UNDO.
CONSTRUCTOR PUBLIC WPFShadowsForm (wpfform AS System.Windows.Window):
SUPER().
InitializeComponent().
IF wpfform <> ? THEN
DO:
THIS-OBJECT:pWPFform = wpfform.
/*Close handler*/
THIS-OBJECT:pWPFform:Closed:Subscribe(THIS-OBJECT:pWPFClosedHandler).
THIS-OBJECT:LOAD:Subscribe(THIS-OBJECT:pLoadHandler).
END.
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END CONSTRUCTOR.
/*Loader de chargement*/
METHOD PRIVATE VOID pLoadHandler(sender AS System.Object,e AS System.EventArgs ):
WAIT-FOR THIS-OBJECT:pWPFform:Show().
END METHOD.
/*Handler de la fermeture de la fenetre WPF*/
METHOD PRIVATE VOID pWPFClosedHandler(sender AS System.Object, e AS System.EventArgs):
THIS-OBJECT:Close().
END METHOD.
/*Initialisation*/
METHOD PRIVATE VOID InitializeComponent( ):
/* NOTE: The following method is automatically generated.
We strongly suggest that the contents of this method only be modified using the
Visual Designer to avoid any incompatible modifications.
Modifying the contents of this method using a code editor will invalidate any support for this file. */
THIS-OBJECT:SuspendLayout().
/* */
/* WPFShadowsForm */
/* */
THIS-OBJECT:ClientSize = NEW System.Drawing.Size(292, 266).
THIS-OBJECT:FormBorderStyle = System.Windows.Forms.FormBorderStyle:None.
THIS-OBJECT:Name = "WPFShadowsForm".
THIS-OBJECT:ShowIcon = FALSE.
THIS-OBJECT:ShowInTaskbar = FALSE.
THIS-OBJECT:Text = "WPFShadowsForm".
THIS-OBJECT:TransparencyKey = System.Drawing.SystemColors:Control.
THIS-OBJECT:ResumeLayout(FALSE).
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END METHOD.
/*DEstructeur*/
DESTRUCTOR PUBLIC WPFShadowsForm ( ):
IF VALID-OBJECT(components) THEN
DO:
CAST(components, System.IDisposable):Dispose().
END.
END DESTRUCTOR.
END CLASS.
/*Code for lunch WPF form*/
DEFINE VARIABLE shadow AS WPFShadowsForm.
shadow = NEW sage.WPF.WPFShadowsForm (wpf).
wpf:SetViewModel(your business object implements C# interface).
WAIT-FOR System.Windows.Forms.Application:Run(shadow).
Now DataBinding CommandBinding with OE data Work!!! ^_^
jmls wrote:
Peter, do you have the steps required to do this ? I've struggled and cannot seem to get a stable config.
Thanks
I'll need to dig around a bit, but I believe I've got the code at least, somewhere.
-- peter