OliverM
Guest
|
On a TaskPane I want to consume events fired by my business object. The business object is created/destroyed on user request and may not yet exist when the TaskPane is created.
Is there a chance to add an internal property to the TaskPane which is set once the business object is created? |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Oliver,
Consider a controller class implementing the Singleton pattern (see https://msdn.microsoft.com/en-us/library/ff650316.aspx). The controller contains a reference to the business object: MyСontroller.Instance.BusinessObject. When the business object gets created, it calls the controller. The controller stores a reference to the newly created business object and informs existing task pane instances about the new business object; the pane instances retrieve the business object and connect to its events. Whenever a new task pane instance gets created, it checks if the business object exists on the controller (in ADXTaskPaneBeforeShow) and connects to its events. When the business objects is about to be destroyed, the controller loops through task pane instances to call a method disconnecting the current instance from the business object.
Andrei Smolin
Add-in Express Team Leader |
|
OliverM
Guest
|
Hi Anrei,
.. and informs existing task pane instances about the new business object; the pane instances retrieve the business object and connect to its events.
I tried to loop through the task pane instances and call a method like
public void SetBusinessObject(SomeObject businessObject)
{
_businessObject = businessObject;
_businessObject.BeforeStartProcessing += businessObject_BeforeStartProcessing;
}
But the task panes does not expose this method. |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
If you talk about an Add-in Express task pane, you need to add that method to the code of the pane class.
Andrei Smolin
Add-in Express Team Leader |
|
OliverM
Guest
|
Issue solved, what tricked me was reading the documentation. It says To access the form, which is currently active in Excel, you use the TaskPaneInstance property of the <Item>;
So I expected the task pane behaves like any other form, I only need to add my udf methods to the class and call them through the TaskPaneInstance object like MyAddInModule.CurrentInstance.adxExcelTaskPanesManager.Items[0].TaskPaneInstance.MyTestMethod();
But it turnes out the TaskPaneInstance object needs to be casted to type ADXExcelTaskPane like
ADXExcelTaskPane myPane = (ADXExcelTaskPane)MyAddInModule.CurrentInstance.adxExcelTaskPanesManager.Items[0].TaskPaneInstances[0];
in order to access udf methods. |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Many thanks for letting us know about this issue. We'll consider reworking this text fragment. Could I ask you to let me know about any other issue(s) that you had(have) with the manual? Thank you in advance.
Andrei Smolin
Add-in Express Team Leader |
|