コード例 #1
0
 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;
         }
     });
 }
コード例 #2
0
        private void PropertiesGrid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var scrollViewer = VisualTreeHelperUtil.GetControlAscendant <ScrollViewer>(this);
            var maxWidth     = scrollViewer.ActualWidth - 10;

            if (propertiesGrid.ActualWidth > maxWidth)
            {
                propertiesGrid.Width = maxWidth;
            }
            else if (propertiesGrid.ActualWidth != maxWidth)
            {
                propertiesGrid.Width = double.NaN;
            }
        }
コード例 #3
0
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            foreach (var relation in VisualTreeHelperUtil.GetControlsDecendant <RelationBase>(this))
            {
                relation.IsSelected = false;
            }

            var typeDesigner = VisualTreeHelperUtil.GetControlAscendant <TypeBaseDesigner>(e.OriginalSource);

            _moveEntityType = typeDesigner != null && VisualTreeHelperUtil.GetControlAscendant <ListView>(e.OriginalSource) == null && VisualTreeHelperUtil.GetControlAscendant <TextBox>(e.OriginalSource) == null;
            if (_moveEntityType)
            {
                _moveEntityTypeStartPoint = e.GetPosition(this);
                Cursor = Cursors.ScrollAll;
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var  separator     = (MenuSeparator)value;
            var  items         = VisualTreeHelperUtil.GetControlAscendant <ItemsControl>(separator).Items.OfType <FrameworkElement>();
            bool visibleBefore = false;
            bool visibleAfter  = false;
            bool before        = true;

            foreach (var item in items)
            {
                if (item is Separator)
                {
                    if (item == separator)
                    {
                        before = false;
                    }
                    else if (item.IsVisible)
                    {
                        if (before)
                        {
                            visibleBefore = false;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else if (item.IsVisible)
                {
                    if (before)
                    {
                        visibleBefore = true;
                    }
                    else
                    {
                        visibleAfter = true;
                    }
                }
            }
            return(visibleBefore && visibleAfter ? Visibility.Visible : Visibility.Collapsed);
        }
コード例 #5
0
ファイル: Expander.cs プロジェクト: ElinamLLC/SharpDeveloper
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);
            if (VisualTreeHelperUtil.GetControlAscendant <TextBox>(e.OriginalSource) == null || VisualTreeHelperUtil.GetControlAscendant <EditableTextBlock>(e.OriginalSource) == null)
            {
                if (!(e.OriginalSource is FrameworkElement))
                {
                    return;
                }

                FrameworkElement control = (FrameworkElement)e.OriginalSource;
                while ((control = VisualTreeHelperUtil.GetControlAscendant <Grid>(control)) != null)
                {
                    if (control.Name == "grdHeader")
                    {
                        ClickOnTheHeader();
                        break;
                    }
                }
            }
        }
コード例 #6
0
 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
 {
     base.OnMouseLeftButtonDown(e);
     if (VisualTreeHelperUtil.GetControlAscendant <EntityTypeDesigner>(e.OriginalSource) == null)
     {
         if (UITypeToAdd == null)
         {
             UnselectAllTypes();
             _startSelectionPoint = e.GetPosition(this);
             _isSelecting         = true;
         }
         else
         {
             AddType(UITypeToAdd, e.GetPosition(this));
             UITypeToAdd = null;
         }
     }
     else
     {
         UITypeToAdd = null;
     }
     Container.Selection = null;
 }
コード例 #7
0
        protected TypeBaseDesigner(IUIType uiType)
        {
            InitializeComponent();
            UIType      = uiType;
            DataContext = UIType;
            InitContextMenuCommandBindings();
            entityTypeExpander.PreviewMouseDown +=
                (sender, e) =>
            {
                if (e.LeftButton == MouseButtonState.Pressed && (MoreThanOneTypeSelected || !(VisualTreeHelperUtil.GetControlAscendant <ListView>(e.OriginalSource) == propertiesListView)))
                {
                    SelectOrUnselect();
                }
                else if (!IsSelected)
                {
                    IsSelected = true;
                }
            };
            if (!Init)
            {
                SizeChangedEventHandler sizeChangedHandler = null;
                sizeChangedHandler = delegate
                {
                    DrawRelations();
                    SizeChanged -= sizeChangedHandler;
                };
                SizeChanged += sizeChangedHandler;
            }
            SizeChanged += delegate { OnMove(); };
            uiType.RelatedPropertyDeleted += uiRelatedProperty =>
            {
                if (RelationsContenerByRelatedProperty.ContainsKey(uiRelatedProperty))
                {
                    Designer.Children.Remove(RelationsContenerByRelatedProperty[uiRelatedProperty]);
                    RelationsContenerByRelatedProperty.Remove(uiRelatedProperty);
                }
            };
            var uiEntityType = uiType as UIEntityType;

            if (uiEntityType != null)
            {
                uiEntityType.AbstractChanged += delegate { entityTypeExpander.GetBindingExpression(TypeBaseExpander.BorderBrushProperty).UpdateTarget(); }
            }
            ;
        }