protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject 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))); DeviceType itemtype = DeviceType.DEV_Init; if (dragObject.UID.StartsWith("0001")) // { itemtype = DeviceType.DEV_BREWER; } else if (dragObject.UID.StartsWith("0002")) // this is for grinder { itemtype = DeviceType.DEV_GRINDER; } else if (dragObject.UID.StartsWith("0003")) // this is for canister { itemtype = DeviceType.DEV_CANISTER; } else if (dragObject.UID.StartsWith("0004")) // this is for mixer { itemtype = DeviceType.DEV_MIXER; } else if (dragObject.UID.StartsWith("000f")) // this is for boiler { itemtype = DeviceType.DEV_BOILER; } else if (dragObject.UID.StartsWith("0008")) // this is for machine { itemtype = DeviceType.DEV_CUP; } else if (dragObject.UID.StartsWith("000c")) // this is for machine { itemtype = DeviceType.DEV_LED; } else if (dragObject.UID.StartsWith("0018")) // this is for machine { itemtype = DeviceType.DEV_DRIP; } else if (dragObject.UID.StartsWith("0019")) // this is for machine { itemtype = DeviceType.DEV_WASTER; } else if (dragObject.UID.StartsWith("001a")) // this is for machine { itemtype = DeviceType.DEV_DOOR; } else if (dragObject.UID.StartsWith("0000-02")) // this is for machine { itemtype = DeviceType.DEV_VIRMACHINE; } if (!isValid(itemtype)) { MessageBox.Show("can not create more!"); return; } if (content != null) { newItem = new DesignerItem(dragObject.UID, this); 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; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); _machineDevicelist.Add(newItem.ID, newItem); SetConnectorDecoratorTemplate(newItem); Control decorator = newItem.Template.FindName("PART_ConnectorDecorator", newItem) as Control; if (dragObject.UID.Equals("0000-00")) // this is for valve { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_valve"); } } else if (dragObject.UID.StartsWith("0001")) // this is for brewer { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_brewer"); } } else if (dragObject.UID.StartsWith("0002")) // this is for grinder { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_grinder"); } } else if (dragObject.UID.StartsWith("0003")) // this is for canister { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_can"); } } else if (dragObject.UID.StartsWith("0004")) // this is for mixer { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_brewer"); } } else if (dragObject.UID.StartsWith("000f")) // this is for boiler { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_boiler"); } } else if (dragObject.UID.StartsWith("000a")) // this is for boiler { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_pump"); } } else if (dragObject.UID.StartsWith("0008")) { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_end"); } } //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; } }
private void SetConnectorDecoratorTemplate(DesignerItem item) { if (item.ApplyTemplate() && item.Content is UIElement) { Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control; if (item.Uid.Equals("0000-00")) // this is for valve { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_valve"); } } else if (item.Uid.StartsWith("0001")) // this is for brewer { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_brewer"); } } else if (item.Uid.StartsWith("0002")) // this is for grinder { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_grinder"); } } else if (item.Uid.StartsWith("0003")) // this is for canister { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_can"); } } else if (item.Uid.StartsWith("0004")) // this is for mixer { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_brewer"); } } else if (item.Uid.StartsWith("000f")) // this is for boiler { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_boiler"); } } else if (item.Uid.StartsWith("000a")) { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_pump"); } } else if (item.Uid.StartsWith("0008")) { if (decorator != null) { decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_end"); } } } }