Social Icons

twitter google plus linkedin rss feed

Pages

6.1.12

Creating Events in Silverlight

I have read it’s impossible in a couple of places, i don’t know if it was in the previous versions, but at least since Silverlight 3 is possible… and even more… easy.

Here is an event I use to check when an item has moved.

        #region Events
        public delegate void PositionChangeHandler(Object Sender);

        public event PositionChangeHandler PositionChangedEvent;

        protected virtual void OnPositionChanged()
        {
            if (PositionChangedEvent != null)
                PositionChangedEvent(this);
        }
        #endregion

And then in the method where I am updating the position of the item:
OnPositionChanged();

After that we can easily hook to the event from the other classes:
ParentObjective.PositionChangedEvent += new Objective.PositionChangeHandler(RelatedObjectives_PositionChangedEvent);

Nice and easy.

No comments:

Post a Comment