locked
How does the Part fire ComponentNotification? RRS feed

  • Question

  • I know how to subscribe to notfications in the View but how does one fire it from the Part? The docs so far haven't been able to tell me that. I do see a FireNotification() in ComponentNotification class, however the notification-connection point is of type: IComponentNotification<T>. Do I need to cast? What is the right approach?


    thanks,
    Pavan
    Wednesday, June 13, 2007 3:33 PM

Answers

  •  Alex Bulankou wrote:

    Call FireNotification() from the part and pass the object that contains information about this notification. Then in your event handler in the view you can analyze ComponentNotificationEventArgs<object>.NotificationData and cast it to the type of your information object.

    In the future CTPs one will be able to use a different generic type for ComponentNotification<object> but for now this is an object. For a brief overview of connection points and when to use what you can check this post.



    Just to clarify, one needs to cast the notification connection point to ComponentNotification and then make the call. By default the generated notification is of type IComponentNotification<T>, which does not have that method.
    Wednesday, June 13, 2007 5:13 PM

All replies

  • Call FireNotification() from the part and pass the object that contains information about this notification. Then in your event handler in the view you can analyze ComponentNotificationEventArgs<object>.NotificationData and cast it to the type of your information object.

    In the future CTPs one will be able to use a different generic type for ComponentNotification<object> but for now this is an object. For a brief overview of connection points and when to use what you can check this post.

    Wednesday, June 13, 2007 4:50 PM
  •  Alex Bulankou wrote:

    Call FireNotification() from the part and pass the object that contains information about this notification. Then in your event handler in the view you can analyze ComponentNotificationEventArgs<object>.NotificationData and cast it to the type of your information object.

    In the future CTPs one will be able to use a different generic type for ComponentNotification<object> but for now this is an object. For a brief overview of connection points and when to use what you can check this post.



    Just to clarify, one needs to cast the notification connection point to ComponentNotification and then make the call. By default the generated notification is of type IComponentNotification<T>, which does not have that method.
    Wednesday, June 13, 2007 5:13 PM
  •  Pavan Podila wrote:
     Alex Bulankou wrote:

    Call FireNotification() from the part and pass the object that contains information about this notification. Then in your event handler in the view you can analyze ComponentNotificationEventArgs<object>.NotificationData and cast it to the type of your information object.

    In the future CTPs one will be able to use a different generic type for ComponentNotification<object> but for now this is an object. For a brief overview of connection points and when to use what you can check this post.



    Just to clarify, one needs to cast the notification connection point to ComponentNotification and then make the call. By default the generated notification is of type IComponentNotification<T>, which does not have that method.

     

    You don't need to cast because you can use the generated private property which is of type ComponentNotification, not IComponentNotification.

    For example if I add:

     

    <AcropolisApplication.ConnectionPoints>

    <Acx:ComponentNotification Name="notification"/>

    </AcropolisApplication.ConnectionPoints>

     

    I can then access it from the part's .cs file:

     

    notificationValue.FireNotification(myObject);

    Wednesday, June 13, 2007 5:25 PM
  • Alex,
         Is there a reason why the private field is of a different type than the generated Property? Just out of curiosity. I assume its some framework level detail to wire things up?


    Pavan
    Wednesday, June 13, 2007 6:02 PM
  •  Pavan Podila wrote:
    Alex,
         Is there a reason why the private field is of a different type than the generated Property? Just out of curiosity. I assume its some framework level detail to wire things up?


    Pavan

     

     

    The Notification property in my example above is generated as public and hence this is public we make it IComponentNotification, because only members of IComponentNotification should be available outside Part. FireNotification() on the other hand should only accessible inside the Part, because the design intention behind ComponentNotification is that the Part itself calls it. So you can use private variable to call FireNotification() however if you want to access the same variable through a property from outside Part you only get what's available in IComonentNotification  (unless of course you cheat and use cast :-))

    Wednesday, June 13, 2007 6:21 PM
  • That makes sense, however it was not obvious that the private field is of a different type Smile
    Wednesday, June 13, 2007 6:50 PM