ExcelTaskPane: How to consume events from another class

Add-in Express™ Support Service
That's what is more important than anything else

ExcelTaskPane: How to consume events from another class
 
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?
Posted 25 Aug, 2016 05:44:59 Top
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
Posted 25 Aug, 2016 06:35:03 Top
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.
Posted 25 Aug, 2016 07:25:34 Top
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
Posted 25 Aug, 2016 07:35:45 Top
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.
Posted 25 Aug, 2016 08:51:58 Top
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
Posted 25 Aug, 2016 09:03:30 Top
OliverM


Guest


Sure I will!
Posted 25 Aug, 2016 09:13:08 Top