Exemple #1
0
        private void UpdateSelection()
        {
            designerCanvas.SelectionService.ClearSelection();

            Rect rubberBand = new Rect(startPoint.Value, endPoint.Value);

            foreach (Control item in designerCanvas.Children)
            {
                Rect itemRect   = VisualTreeHelper.GetDescendantBounds(item);
                Rect itemBounds = item.TransformToAncestor(designerCanvas).TransformBounds(itemRect);

                if (rubberBand.Contains(itemBounds))
                {
                    if (item is ViewModelConnection)
                    {
                        designerCanvas.SelectionService.AddToSelection(item as IModelSelectable);
                    }
                    else
                    {
                        ViewModelDesignerItem di = item as ViewModelDesignerItem;
                        if (di.ParentID == Guid.Empty)
                        {
                            designerCanvas.SelectionService.AddToSelection(di);
                        }
                    }
                }
            }
        }
Exemple #2
0
 void DesignerItem_Loaded(object sender, RoutedEventArgs e)
 {
     if (base.Template != null)
     {
         ContentPresenter contentPresenter =
             this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter;
         if (contentPresenter != null)
         {
             if (VisualTreeHelper.GetChildrenCount(contentPresenter) > 0)
             {
                 UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
                 if (contentVisual != null)
                 {
                     DragThumb thumb = this.Template.FindName("PART_DragThumb", this) as DragThumb;
                     if (thumb != null)
                     {
                         ControlTemplate template =
                             ViewModelDesignerItem.GetDragThumbTemplate(contentVisual) as ControlTemplate;
                         if (template != null)
                         {
                             thumb.Template = template;
                         }
                     }
                 }
             }
         }
     }
 }
 private void SetConnectorDecoratorTemplate(ViewModelDesignerItem item)
 {
     if (item.ApplyTemplate() && item.Content is UIElement)
     {
         ControlTemplate template  = ViewModelDesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement);
         Control         decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control;
         if (decorator != null && template != null)
         {
             decorator.Template = template;
         }
     }
 }
        protected override void OnDrop(DragEventArgs e)
        {
            Type t = e.GetType();

            base.OnDrop(e);
            ModelDragObject        dragObject    = e.Data.GetData(typeof(ModelDragObject)) as ModelDragObject;
            ModelCanvasStateObject state         = new ModelCanvasStateObject();
            PropertyGrid           SelectedPgrid = new PropertyGrid();

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                ViewModelDesignerItem newItem = null;
                Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));
                if (content != null)
                {
                    newItem = new ViewModelDesignerItem();
                    DockPanel pnl = (DockPanel)content;

                    string StateBrandName = pnl.ToolTip.ToString();
                    if (StateBrandName != "P" && StateBrandName != "GENERIC")
                    {
                        string StateBrandId = ConfigurationManager.AppSettings[StateBrandName];
                        if (CurrentBrandId != StateBrandId)
                        {
                            return;
                        }
                    }


                    state.Id = avaliableStateNumberList[0].ToString();
                    avaliableStateNumberList.Remove(state.Id);
                    // GetStateType(pnl.Tag.ToString());
                    state.Type      = pnl.Tag.ToString();
                    pnl.Name        = state.Type + state.Id.ToString();
                    pnl.Uid         = state.Id;
                    state.dockPanel = pnl;
                    content         = pnl;

                    Type   ClassType     = Type.GetType("ATMDesigner.UI.States.State" + pnl.Tag.ToString());
                    Object ClassInstance = Activator.CreateInstance(ClassType, this);

                    PropertyInfo StateNo = ClassType.GetProperty("StateNumber");
                    StateNo.SetValue(ClassInstance, state.Id, null);
                    PropertyInfo BrandId = ClassType.GetProperty("BrandId");
                    BrandId.SetValue(ClassInstance, CurrentBrandId, null);
                    PropertyInfo ConfigId = ClassType.GetProperty("ConfigId");
                    ConfigId.SetValue(ClassInstance, CurrentConfigId, null);

                    SelectedPgrid.SelectedObject     = ClassInstance;
                    SelectedPgrid.SelectedObjectName = state.Id;

                    state.PropertyGrid    = SelectedPgrid;
                    state.TransactionName = CurrentTransactionName;
                    state.BrandId         = CurrentBrandId;
                    state.ConfigId        = CurrentConfigId;
                    newItem.Content       = content;
                    Point position = e.GetPosition(this);

                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        ViewModelDesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        ViewModelDesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        ViewModelDesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        ViewModelDesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }
                    newItem.StateName   = state.Type;
                    newItem.StateNumber = state.Id;
                    TransactionList.Add(state);
                    Canvas.SetZIndex(newItem, this.Children.Count);
                    this.Children.Add(newItem);
                    SetConnectorDecoratorTemplate(newItem);
                    this.SelectionService.SelectItem(newItem);
                    newItem.Focus();
                }

                e.Handled = true;
            }
        }