本文整理汇总了C#中Organization.FireSomethingHappenedEvent方法的典型用法代码示例。如果您正苦于以下问题:C# Organization.FireSomethingHappenedEvent方法的具体用法?C# Organization.FireSomethingHappenedEvent怎么用?C# Organization.FireSomethingHappenedEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Organization
的用法示例。
在下文中一共展示了Organization.FireSomethingHappenedEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
PopulatedOrganization wonkaFactory = new PopulatedOrganization();
Organization chocolateDepartment = new Organization();
#region SINGLE OBJECT EVENT BINDING
// create the event binding for single object
EventBinding<Organization, string> eventBinding =
new EventBinding<Organization, string>();
// specify the source object and the path to the source binding property that contains the event
// we want to bind to
eventBinding.SourceObj = wonkaFactory;
eventBinding.SourcePathLinks =
StringCodePathResolver.ResolveStringPath("TheMostImportantDepartment").ToList();
// do the binding itself
eventBinding.Bind();
// specify the event name (it can be done either before or after bind()
// method is called
eventBinding.EventName = "SomethingHappenedInOrgEvent";
// add the event hanlder whose signature is similar to that of
// SomethingHappenedInOrgEvent event to the binding
eventBinding.TheEvent += eventBinding_SomethingHappenedInTheDepartment;
// nothing is printed to the console because wonkaFactory.TheMostImportantDepartment
// is still not set to chocolateDepartment object
chocolateDepartment.FireSomethingHappenedEvent("Augustus Gloop went to the chocolate creek. (Before the department added - should not show)" );
// set wonkaFactory.TheMostImportantDepartment
wonkaFactory.TheMostImportantDepartment = chocolateDepartment;
// this message is printed on the console
chocolateDepartment.FireSomethingHappenedEvent("Augustus Gloop is out of the game (should show)");
// unbind the event
eventBinding.Unbind();
#endregion SINGLE OBJECT EVENT BINDING
#region COLLECTION EVENT BINDING
// create the collection AllDepartments
wonkaFactory.AllDepartments = new ObservableCollection<Organization>();
// add chocolate department to it
wonkaFactory.AllDepartments.Add(chocolateDepartment);
// create collection event binding
CollectionEventBinding<Organization, string> collectionEventBinding =
new CollectionEventBinding<Organization, string>();
// set the objects that contain the event we want to bind to
// to be "AllDepartments" collection property of "wonkaFactory" object
collectionEventBinding.SourceObj = wonkaFactory;
collectionEventBinding.SourcePathLinks =
StringCodePathResolver.ResolveStringPath("AllDepartments").ToList();
// bind the event
collectionEventBinding.Bind();
// set the event name (can be done before or after the binding)
collectionEventBinding.EventName = "SomethingHappenedInOrgEvent";
// add event handler
collectionEventBinding.TheEvent += collectionEventBinding_TheEvent;
// create gumDepartment
Organization gumDepartment = new Organization();
// fire an event (should not be handled since gumDepartment is not part of the collection yet)
gumDepartment.FireSomethingHappenedEvent("We had great sales (Before the department is added - should not show)");
// Add gum department to the collection
wonkaFactory.AllDepartments.Add(gumDepartment);
// fire the event (should be handled, since now gumDepartment is part of the collection)
gumDepartment.FireSomethingHappenedEvent("We had great sales (After the department is added - should show)");
// remove gum department from All Department collection
// collectionEventBinding should be sufficiently smart to disconnect
// the event of gumDepartment object from the handler
wonkaFactory.AllDepartments.Remove(gumDepartment);
// fire the event again - (the handler should not run, since gumDepartment has been removed from the collection)
gumDepartment.FireSomethingHappenedEvent("We had great sales (After the department is Removed - should not show)");
#endregion COLLECTION EVENT BINDING
}