Exemplo n.º 1
0
 public Element(InitialElement initialElement, ElementProperties elementProperties)
 {
   InitialElement = initialElement;
   ElementProperties = elementProperties;
   Connectors = new List<ConnectorModel>();
 }
Exemplo n.º 2
0
    protected override void OnDrop(DragEventArgs e)
    {
      base.OnDrop(e);
      var dragObject = e.Data.GetData(typeof (DragObject)) as DragObject;
      if (dragObject != null) // && !String.IsNullOrEmpty(dragObject.Xaml))
      {
        DesignerItem newItem = null;
        //Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));
        var content = "";
        if (content != null)
        {
          var vm = DataContext as EditorWindowViewModel;
          if (vm == null)
          {
            throw new ArgumentException("DataContext as ConstructorViewModel");
            return;
          }

          var visualProperties = new VisualProperties();
          //visualProperties.Size = 
          var elementProperties = new ElementProperties(visualProperties, new DomainProperties());
          var initialElement = dragObject.InitialElementViewModel.InitialElement;
          var model = new Element(initialElement, elementProperties);
          var elementViewModel = new ElementViewModel(model);
          elementViewModel.ElementPropertiesViewModel.Name = string.Format("{0} {1}", initialElement.Name, count++);
          newItem = new DesignerItem(elementViewModel);

          newItem.SizeChanged += (sender, args) =>
          {
            var newSize = args.NewSize;
            elementViewModel.ElementPropertiesViewModel.ElementVisualPropertiesViewModel.Size = new ElementSize(newSize.Height, newSize.Width);
          };

          var button = new Ellipse
          {
            //Width = 100,
            //Height = 100,
            Fill = Brushes.Aqua
          };
          newItem.Content = ResourceUtil.GetResourceByName(dragObject.InitialElementViewModel.StyleName) ?? button;

          var position = e.GetPosition(this);

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

            SetLeft(newItem, Math.Max(0, position.X - newItem.Width/2));
            SetTop(newItem, Math.Max(0, position.Y - newItem.Height/2));
          }
          else
          {
            SetLeft(newItem, Math.Max(0, position.X));
            SetTop(newItem, Math.Max(0, position.Y));
          }

          newItem.SetCoords();

          SetZIndex(newItem, Children.Count);
          Children.Add(newItem);
          SetConnectorDecoratorTemplate(newItem);

          //update selection
          SelectionService.SelectItem(newItem);
          newItem.Focus();

          vm.Add(newItem.ElementViewModel);

        }

        e.Handled = true;
      }
    }
 public ElementPropertiesViewModel(ElementProperties elementProperties)
 {
   this.elementProperties = elementProperties;
   ElementVisualPropertiesViewModel = new ElementVisualPropertiesViewModel(elementProperties.VisualProperties);
 }