public static ExecutedRoutedEventHandler AddAssociationExecuted(UIElement parent, Func <CSDLView> getCSDLView, Func <DesignerView> getDesignerView, UIEntityType defaultEntityType1, Action <UIAssociation> specialActionToDoWhenNewItemAdded)
 {
     return((object sender, ExecutedRoutedEventArgs e) =>
     {
         var csdlView = getCSDLView();
         var designerView = getDesignerView();
         var addAssociationWindow = new AddAssociationWindow {
             Owner = VisualTreeHelperUtil.GetControlAscendant <Window>(parent), DataContext = csdlView, NavigationProperty1EntityType = defaultEntityType1
         };
         switch (addAssociationWindow.ShowDialog())
         {
         case true:
             var uiAssociation = csdlView.AddAssociation(addAssociationWindow.AssociationName, addAssociationWindow.NavigationProperty1Name, addAssociationWindow.NavigationProperty1EntityType, addAssociationWindow.NavigationProperty1Cardinality.Value, addAssociationWindow.NavigationProperty2Name, addAssociationWindow.NavigationProperty2EntityType, addAssociationWindow.NavigationProperty2Cardinality.Value);
             SizeChangedEventHandler actionToDoWhenNewItemAdded = null;
             bool drawAssociation = false;
             DesignerCanvas designerCanvas = parent as DesignerCanvas;
             if (designerCanvas == null)
             {
                 designerCanvas = VisualTreeHelperUtil.GetControlAscendant <DesignerCanvas>(parent);
             }
             var navigationProperty1EntityTypeDesigner = designerCanvas.GetTypeDesigner(uiAssociation.NavigationProperty1.ParentType);
             var navigationProperty2EntityTypeDesigner = designerCanvas.GetTypeDesigner(uiAssociation.NavigationProperty2.ParentType);
             actionToDoWhenNewItemAdded =
                 (object o, SizeChangedEventArgs scea) =>
             {
                 if (designerView.ContainsEntityType(uiAssociation.NavigationProperty1.ParentType) && designerView.ContainsEntityType(uiAssociation.NavigationProperty2.ParentType))
                 {
                     if (drawAssociation)
                     {
                         navigationProperty1EntityTypeDesigner.DrawAssociation(navigationProperty2EntityTypeDesigner, uiAssociation.NavigationProperty1.BusinessInstance as NavigationProperty);
                     }
                     else
                     {
                         drawAssociation = true;
                     }
                 }
                 if (specialActionToDoWhenNewItemAdded != null)
                 {
                     specialActionToDoWhenNewItemAdded(uiAssociation);
                 }
                 ((ListView)o).SizeChanged -= actionToDoWhenNewItemAdded;
             };
             navigationProperty1EntityTypeDesigner.propertiesListView.SizeChanged += actionToDoWhenNewItemAdded;
             if (navigationProperty2EntityTypeDesigner != null)
             {
                 navigationProperty2EntityTypeDesigner.propertiesListView.SizeChanged += actionToDoWhenNewItemAdded;
             }
             break;
         }
     });
 }