protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { // XamlWriter.Save() has limitations in exactly what is serialized, // see SDK documentation; short term solution only; string xamlString = XamlWriter.Save(this.Content); ModelDragObject dataObject = new ModelDragObject(); dataObject.Xaml = xamlString; WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel; if (panel != null) { // desired size for DesignerCanvas is the stretched Toolbox item size double scale = 1.3; dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale); } DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); e.Handled = true; } }
//ViewProperties on Drop to canvas private void TransactionDiagram_PreviewDrop(object sender, DragEventArgs e) { ViewModelDesignerCanvas dcanvas = new ViewModelDesignerCanvas(); dcanvas = (ViewModelDesignerCanvas)sender; SelectedPgrid = new PropertyGrid(); TreeViewItem ChildNode = new TreeViewItem(); ChildNode = TreeFlow.SelectedItem as TreeViewItem; ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(ChildNode); TreeViewItem parentNode = parent as TreeViewItem; if (parentNode != null && !String.IsNullOrEmpty(parentNode.Header.ToString())) { dcanvas.ProjectName = parentNode.Header.ToString(); dcanvas.CurrentTransactionName = TransDiagramName.Header.ToString(); ModelDragObject dragObject = e.Data.GetData(typeof(ModelDragObject)) as ModelDragObject; ModelCanvasStateObject state = new ModelCanvasStateObject(); 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 (dcanvas.CurrentBrandId != StateBrandId) { MessageBox.Show("Kullanmak istediğiniz State " + StateBrandName + " için sadece kullanılabilir, lütfen Mevcut Brande uygun State kullanınız"); return; } } string frmName = "State" + pnl.Tag.ToString(); string Id = dcanvas.avaliableStateNumberList[0].ToString(); Type ClassType = Type.GetType("ATMDesigner.UI.States." + frmName); Object ClassInstance = Activator.CreateInstance(ClassType); PropertyInfo StateNo = ClassType.GetProperty("StateNumber"); StateNo.SetValue(ClassInstance, Id, null); propertyGrid.SelectedObject = ClassInstance; propertyGrid.SelectedObjectName = Id; SelectedPgrid.SelectedObject = ClassInstance; SelectedPgrid.SelectedObjectName = Id; PropertyGridList.Add(SelectedPgrid); } } } }
//on Drag Drop event private void ViewPropertyGrid(object param) { DragEventArgs e = param as DragEventArgs; ViewModelDesignerCanvas dcanvas = new ViewModelDesignerCanvas(); //dcanvas = (ViewModelDesignerCanvas)sender; //SelectedPgrid = new PropertyGrid(); ModelDragObject dragObject = e.Data.GetData(typeof(ModelDragObject)) as ModelDragObject; ModelCanvasStateObject state = new ModelCanvasStateObject(); 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 frmName = "State" + pnl.Tag.ToString(); string Id = (dcanvas.avaliableStateNumberList[dcanvas.TransactionList.Count]).ToString(); state.Type = pnl.Tag.ToString(); Type CAType = Type.GetType("ATMDesigner.UI.States." + frmName); Object myObj = Activator.CreateInstance(CAType); PropertyInfo StateNo = CAType.GetProperty("StateNumber"); StateNo.SetValue(myObj, Id, null); PropertyInfo stateType = CAType.GetProperty("StateType"); stateType.SetValue(myObj, pnl.Tag.ToString(), null); PropertyInfo Desc = CAType.GetProperty("StateDescription"); Desc.SetValue(myObj, frmName, null); StateObj = myObj; } } }
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; } }