PhysicalTopology _PhysicalTopology_DragDrop; //拖拽进入的父节点 private void DropHelperTreeView0_DragDrop_Over(object arg1, System.Windows.DragEventArgs arg2) { TreeViewDataProvider <ItemsControl, TreeViewItem> dataProvider = GetData(arg2) as TreeViewDataProvider <ItemsControl, TreeViewItem>; TreeViewItem _TreeViewItem = dataProvider.SourceObject as TreeViewItem; _PhysicalTopology_Drag = _TreeViewItem.Tag as PhysicalTopology; TreeViewItem _TreeViewItemP = arg2.Source as TreeViewItem; // Area _Area = _TreeViewItem.Tag as TD; if (_TreeViewItemP == null) { return; } if (_TreeViewItemP.Tag != null) { _PhysicalTopology_DragDrop = _TreeViewItemP.Tag as PhysicalTopology; } if (_TreeViewItemP != null) { if (_PhysicalTopology_Drag.ParentId != _PhysicalTopology_DragDrop.Id) // 平行移动就不需要跟新数据了 { _PhysicalTopology_Drag.ParentId = _PhysicalTopology_DragDrop.Id; //Area area = _PhysicalTopology_Drag.ToDbModel(); //Bll _bll = new Bll(); //_bll.Areas.Edit(area); } } }
public RoomTreeViewDragDropManager(TreeView treeView) { TreeViewDataProvider <ItemsControl, TreeViewItem> treeViewDataProvider = new TreeViewDataProvider <ItemsControl, TreeViewItem>("TreeViewItemObject"); // Data Consumer RoomTreeViewDataConsumer <ItemsControl, TreeViewItem> treeViewDataConsumer = new RoomTreeViewDataConsumer <ItemsControl, TreeViewItem>(new string[] { "TreeViewItemObject" }); // Drag Managers DragManager dragHelperTreeView0 = new DragManager(treeView, treeViewDataProvider); // Drop Managers DropManager dropHelperTreeView0 = new DropManager(treeView, new IDataConsumer[] { treeViewDataConsumer, }); }
public TreeViewDragDropManager(TreeView treeView) { TreeViewDataProvider <ItemsControl, TreeViewItem> treeViewDataProvider = new TreeViewDataProvider <ItemsControl, TreeViewItem>("TreeViewItemObject"); // Data Consumer TreeViewDataConsumer <ItemsControl, TreeViewItem> treeViewDataConsumer = new TreeViewDataConsumer <ItemsControl, TreeViewItem>(new string[] { "TreeViewItemObject" }); // Drag Managers DragManager dragHelperTreeView0 = new DragManager(treeView, treeViewDataProvider); DropManager dropHelperTreeView0 = new DropManager(treeView, new IDataConsumer[] { treeViewDataConsumer, }); dropHelperTreeView0.DragDrop_Drop += DropHelperTreeView0_DragDrop_Over; dropHelperTreeView0.DragDrop_Enter += DropHelperTreeView0_DragDrop_Enter; }
private T GetEntityData <T>(DragEventArgs e) where T : class { TreeViewDataProvider <TContainer, TObject> dataProvider = GetData(e) as TreeViewDataProvider <TContainer, TObject>; if (dataProvider != null) { TContainer dragSourceContainer = dataProvider.SourceContainer as TContainer; TreeViewItem dragSourceObject = dataProvider.SourceObject as TreeViewItem; if (dragSourceObject != null) { T entityData = dragSourceObject.Tag as T; return(entityData); } } return(null); }
public MainWindow() { InitializeComponent(); // Used by TabControl, TreeView and ListBox. // This data consumer allows items to be created // from a file or files dragged from Windows Explorer. FileDropConsumer fileDropDataConsumer = new FileDropConsumer(new string[] { "FileDrop", "FileNameW", }); #region T A B C O N T R O L // Data Provider TabControlDataProvider <TabControl, TabItem> tabControlDataProvider = new TabControlDataProvider <TabControl, TabItem>("TabItemObject"); // Data Consumer TabControlDataConsumer <TabControl, TabItem> tabControlDataConsumer = new TabControlDataConsumer <TabControl, TabItem>(new string[] { "TabItemObject" }); // Drag Managers DragManager dragHelperTabControl0 = new DragManager(this.docTabControl0, tabControlDataProvider); DragManager dragHelperTabControl1 = new DragManager(this.docTabControl1, tabControlDataProvider); // Drop Managers DropManager dropHelperTabControl0 = new DropManager(this.docTabControl0, new IDataConsumer[] { tabControlDataConsumer, fileDropDataConsumer }); DropManager dropHelperTabControl1 = new DropManager(this.docTabControl1, new IDataConsumer[] { tabControlDataConsumer, fileDropDataConsumer }); #endregion #region T R E E V I E W // Data Provider TreeViewDataProvider <ItemsControl, TreeViewItem> treeViewDataProvider = new TreeViewDataProvider <ItemsControl, TreeViewItem>("TreeViewItemObject"); // Data Consumer TreeViewDataConsumer <ItemsControl, TreeViewItem> treeViewDataConsumer = new TreeViewDataConsumer <ItemsControl, TreeViewItem>(new string[] { "TreeViewItemObject" }); // Data Consumer of ListBoxItems ListBoxItemToTreeViewItem <ListBox, ListBoxItem> listBoxItemToTreeViewItem = new ListBoxItemToTreeViewItem <ListBox, ListBoxItem>(new string[] { "ListBoxItemObject" }); // Drag Managers DragManager dragHelperTreeView0 = new DragManager(this.treeView0, treeViewDataProvider); DragManager dragHelperTreeView1 = new DragManager(this.treeView1, treeViewDataProvider); // Drop Managers DropManager dropHelperTreeView0 = new DropManager(this.treeView0, new IDataConsumer[] { treeViewDataConsumer, listBoxItemToTreeViewItem, fileDropDataConsumer, }); DropManager dropHelperTreeView1 = new DropManager(this.treeView1, new IDataConsumer[] { treeViewDataConsumer, listBoxItemToTreeViewItem, fileDropDataConsumer, }); #endregion #region L I S T B O X // Data Provider ListBoxDataProvider <ListBox, ListBoxItem> listBoxDataProvider = new ListBoxDataProvider <ListBox, ListBoxItem>("ListBoxItemObject"); // Data Consumer ListBoxDataConsumer <ListBox, ListBoxItem> listBoxDataConsumer = new ListBoxDataConsumer <ListBox, ListBoxItem>(new string[] { "ListBoxItemObject" }); // Data Consumer of TreeViewItems TreeViewItemToListBoxItem <ItemsControl, TreeViewItem> treeViewItemToListBoxItem = new TreeViewItemToListBoxItem <ItemsControl, TreeViewItem>(new string[] { "TreeViewItemObject" }); // Drag Managers DragManager dragHelperListBox0 = new DragManager(this.listBox0, listBoxDataProvider); DragManager dragHelperListBox1 = new DragManager(this.listBox1, listBoxDataProvider); // Drop Managers DropManager dropHelperListBox0 = new DropManager(this.listBox0, new IDataConsumer[] { listBoxDataConsumer, treeViewItemToListBoxItem, fileDropDataConsumer, }); DropManager dropHelperListBox1 = new DropManager(this.listBox1, new IDataConsumer[] { listBoxDataConsumer, treeViewItemToListBoxItem, fileDropDataConsumer, }); #endregion #region T R A S H // Data Consumer TrashConsumer trashConsumer = new TrashConsumer(new string[] { "TabItemObject", "TreeViewItemObject", "ListBoxItemObject", "CanvasTextBlockObject", "CanvasRectangleObject", "CanvasButtonObject", "ToolbarButtonObject", }); // Drop Manager DropManager dropHelperListBoxItemTrash = new DropManager(this.trash, trashConsumer); #endregion #region C A N V A S // Data Providers/Consumers CanvasDataProvider <Canvas, TextBlock> canvasTextBlockDataProvider = new CanvasDataProvider <Canvas, TextBlock>("CanvasTextBlockObject"); CanvasDataConsumer <Canvas, TextBlock> canvasTextBlockDataConsumer = new CanvasDataConsumer <Canvas, TextBlock>(new string[] { "CanvasTextBlockObject" }); CanvasDataProvider <Canvas, Rectangle> canvasRectangleDataProvider = new CanvasDataProvider <Canvas, Rectangle>("CanvasRectangleObject"); CanvasDataConsumer <Canvas, Rectangle> canvasRectangleDataConsumer = new CanvasDataConsumer <Canvas, Rectangle>(new string[] { "CanvasRectangleObject" }); CanvasDataProvider <Canvas, Button> canvasButtonDataProvider = new CanvasDataProvider <Canvas, Button>("CanvasButtonObject"); CanvasDataConsumer <Canvas, Button> canvasButtonDataConsumer = new CanvasDataConsumer <Canvas, Button>(new string[] { "CanvasButtonObject" }); // Data Consumer of Toolbar Buttons ToolbarButtonToCanvasButton <ToolBar, Button> toolbarButtonToCanvasButton = new ToolbarButtonToCanvasButton <ToolBar, Button>(new string[] { "ToolbarButtonObject" }); // Data consumer of System.Strings (creates a TextBlock) StringToCanvasTextBlock systemStringToCanvasTextBlock = new StringToCanvasTextBlock(new string[] { "System.String" }); // Drag Managers DragManager dragHelperCanvas0 = new DragManager(this.canvas0, new IDataProvider[] { canvasTextBlockDataProvider, canvasRectangleDataProvider, canvasButtonDataProvider, }); DragManager dragHelperCanvas1 = new DragManager(this.canvas1, new IDataProvider[] { canvasTextBlockDataProvider, canvasRectangleDataProvider, canvasButtonDataProvider, }); // Drop Managers DropManager dropHelperCanvas0 = new DropManager(this.canvas0, new IDataConsumer[] { canvasTextBlockDataConsumer, canvasRectangleDataConsumer, canvasButtonDataConsumer, toolbarButtonToCanvasButton, systemStringToCanvasTextBlock, }); DropManager dropHelperCanvas1 = new DropManager(this.canvas1, new IDataConsumer[] { canvasTextBlockDataConsumer, canvasRectangleDataConsumer, canvasButtonDataConsumer, toolbarButtonToCanvasButton, systemStringToCanvasTextBlock, }); #endregion #region T O O L B A R // Data Provider ToolBarDataProvider <ToolBar, Button> toolBarButtonDataProvider = new ToolBarDataProvider <ToolBar, Button>("ToolbarButtonObject"); // Data Consumer ToolBarDataConsumer <ToolBar, Button> toolBarButtonDataConsumer = new ToolBarDataConsumer <ToolBar, Button>(new string[] { "ToolbarButtonObject" }); // Data Consumer of Canvas Buttons CanvasButtonToToolbarButton <Canvas, Button> canvasButtonToToolbarButton = new CanvasButtonToToolbarButton <Canvas, Button>(new string[] { "CanvasButtonObject" }); // Drag Managers DragManager dragHelperToolBar0 = new DragManager(this.toolBar0, new IDataProvider[] { toolBarButtonDataProvider, }); DragManager dragHelperToolBar1 = new DragManager(this.toolBar1, new IDataProvider[] { toolBarButtonDataProvider, }); // Drop Managers DropManager dropHelperToolBar0 = new DropManager(this.toolBar0, new IDataConsumer[] { toolBarButtonDataConsumer, canvasButtonToToolbarButton, }); DropManager dropHelperToolBar1 = new DropManager(this.toolBar1, new IDataConsumer[] { toolBarButtonDataConsumer, canvasButtonToToolbarButton, }); #endregion }
/// <summary> /// 拖动节点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="isDrop">false:能否拖动,true:实际拖动</param> /// <returns></returns> private bool DragDropNode(object sender, DragEventArgs e, bool isDrop) { bool isCancel = true; TreeViewDataProvider <TContainer, TObject> dataProvider = GetData(e) as TreeViewDataProvider <TContainer, TObject>; if (dataProvider == null) { Log.Error("RoomTreeViewDataConsumer.DragDropNode", "dataProvider == null"); return(isCancel); } TContainer dragSourceContainer = dataProvider.SourceContainer as TContainer; TreeViewItem dragSourceObject = dataProvider.SourceObject as TreeViewItem;//拖动的源节点 if (dragSourceObject == null) { Log.Error("RoomTreeViewDataConsumer.DragDropNode", "dragSourceObject == null"); return(isCancel); } TreeViewItem newParentNode = e.Source as TreeViewItem;//拖动的目标节点 if (newParentNode == null) { Log.Error("RoomTreeViewDataConsumer.DragDropNode", "newParentNode == null"); return(isCancel); } //dragSourceObject.IsDraging = true; //newParentNode.IsDraging = true; ////A.机房设备移入移出文件夹(分组) //if (newParentNode is TreeViewItemFolder)//拖动机房设备到文件夹 //{ // DeviceFolder folder = newParentNode.Tag as DeviceFolder; // if (dragSourceObject.Tag is RoomDev)//拖动的是机房设备 // { // RoomDev roomDev = dragSourceObject.Tag as RoomDev; // if (dragSourceObject.Parent is TreeViewItemRoom)//A.1 将机房设备移入文件夹 // { // if (roomDev.PId == folder.PId)//必须是同一个机房内的操作 // { // if (isDrop) // { // AddRoomDevToFolder(folder, roomDev); // //base.DragOverOrDrop(true, sender, e); // } // isCancel = false; // } // } // else if (dragSourceObject.Parent is TreeViewItemFolder)//A.2 将机房设备从一个文件夹移动到另一个文件夹 // { // DeviceFolder folderOld = (dragSourceObject.Parent as TreeViewItemFolder).Tag as DeviceFolder; // if (roomDev.PId == folder.PId && folderOld.Id != folder.Id) // { // if (isDrop) // { // MoveRoomDevBetweenFolder(folder, roomDev, folderOld); // //base.DragOverOrDrop(true, sender, e); // } // isCancel = false; // } // } // else // { // } // } //} //else if (newParentNode is TreeViewItemRoom) ////1.将机房设备从文件夹中移动到机房下 //{ // Room room = newParentNode.Tag as Room; // if (dragSourceObject.Tag is RoomDev) // { // RoomDev roomDev = dragSourceObject.Tag as RoomDev; // if (dragSourceObject.Parent is TreeViewItemFolder)//A.3 将机房设备从一个文件夹移除 // { // DeviceFolder folderOld = (dragSourceObject.Parent as TreeViewItem).Tag as DeviceFolder; // if (folderOld.PId == roomDev.PId && roomDev.PId == room.Id)//必须是同一个机房内的操作 // { // if (isDrop) // { // RemoveRoomDevFromFolder(roomDev, folderOld);//将机房设备从一个文件夹移除 // //base.DragOverOrDrop(true, sender, e); // } // isCancel = false; // } // } // else // { // } // } //} //else if (e.Source is TreeViewItemDep) ////1.将机房节点拖动到一个区域节点下 //{ // Dep depNew = newParentNode.Tag as Dep;//新区域 // if (dragSourceObject.Tag is Room)//拖动机房 // { // Room room = dragSourceObject.Tag as Room; // if (depNew.Id != room.PId)//不同区域节点 // { // if (isDrop) // { // MoveRoom(depNew, room); // } // isCancel = false; // } // } // if (dragSourceObject.Tag is Dep)//拖动区域 // { // Dep dep = dragSourceObject.Tag as Dep; // if (depNew.Id != dep.PId)//不同区域节点 // { // if (isDrop) // { // ThreadHelper.Run(() => // { // dep.PId = depNew.Id; // DepDevDataAccess depDa = new DepDevDataAccess(); // depDa.Modify(dep); // depNew.AddDep(dep); // }); // } // isCancel = false; // } // } //} //else //{ //} //dragSourceObject.IsDraging = false; //newParentNode.IsDraging = false; return(isCancel); }
public MainWindow() { InitializeComponent(); // Used by TabControl, TreeView and ListBox. // This data consumer allows items to be created // from a file or files dragged from Windows Explorer. FileDropConsumer fileDropDataConsumer = new FileDropConsumer(new string[] { "FileDrop", "FileNameW", }); #region T A B C O N T R O L // Data Provider TabControlDataProvider<TabControl, TabItem> tabControlDataProvider = new TabControlDataProvider<TabControl, TabItem>("TabItemObject"); // Data Consumer TabControlDataConsumer<TabControl, TabItem> tabControlDataConsumer = new TabControlDataConsumer<TabControl, TabItem>(new string[] { "TabItemObject" }); // Drag Managers DragManager dragHelperTabControl0 = new DragManager(this.docTabControl0, tabControlDataProvider); DragManager dragHelperTabControl1 = new DragManager(this.docTabControl1, tabControlDataProvider); // Drop Managers DropManager dropHelperTabControl0 = new DropManager(this.docTabControl0, new IDataConsumer[] { tabControlDataConsumer, fileDropDataConsumer }); DropManager dropHelperTabControl1 = new DropManager(this.docTabControl1, new IDataConsumer[] { tabControlDataConsumer, fileDropDataConsumer }); #endregion #region T R E E V I E W // Data Provider TreeViewDataProvider<ItemsControl, TreeViewItem> treeViewDataProvider = new TreeViewDataProvider<ItemsControl, TreeViewItem>("TreeViewItemObject"); // Data Consumer TreeViewDataConsumer<ItemsControl, TreeViewItem> treeViewDataConsumer = new TreeViewDataConsumer<ItemsControl, TreeViewItem>(new string[] { "TreeViewItemObject" }); // Data Consumer of ListBoxItems ListBoxItemToTreeViewItem<ListBox, ListBoxItem> listBoxItemToTreeViewItem = new ListBoxItemToTreeViewItem<ListBox, ListBoxItem>(new string[] { "ListBoxItemObject" }); // Drag Managers DragManager dragHelperTreeView0 = new DragManager(this.treeView0, treeViewDataProvider); DragManager dragHelperTreeView1 = new DragManager(this.treeView1, treeViewDataProvider); // Drop Managers DropManager dropHelperTreeView0 = new DropManager(this.treeView0, new IDataConsumer[] { treeViewDataConsumer, listBoxItemToTreeViewItem, fileDropDataConsumer, }); DropManager dropHelperTreeView1 = new DropManager(this.treeView1, new IDataConsumer[] { treeViewDataConsumer, listBoxItemToTreeViewItem, fileDropDataConsumer, }); #endregion #region L I S T B O X // Data Provider ListBoxDataProvider<ListBox, ListBoxItem> listBoxDataProvider = new ListBoxDataProvider<ListBox, ListBoxItem>("ListBoxItemObject"); // Data Consumer ListBoxDataConsumer<ListBox, ListBoxItem> listBoxDataConsumer = new ListBoxDataConsumer<ListBox, ListBoxItem>(new string[] { "ListBoxItemObject" }); // Data Consumer of TreeViewItems TreeViewItemToListBoxItem<ItemsControl, TreeViewItem> treeViewItemToListBoxItem = new TreeViewItemToListBoxItem<ItemsControl, TreeViewItem>(new string[] { "TreeViewItemObject" }); // Drag Managers DragManager dragHelperListBox0 = new DragManager(this.listBox0, listBoxDataProvider); DragManager dragHelperListBox1 = new DragManager(this.listBox1, listBoxDataProvider); // Drop Managers DropManager dropHelperListBox0 = new DropManager(this.listBox0, new IDataConsumer[] { listBoxDataConsumer, treeViewItemToListBoxItem, fileDropDataConsumer, }); DropManager dropHelperListBox1 = new DropManager(this.listBox1, new IDataConsumer[] { listBoxDataConsumer, treeViewItemToListBoxItem, fileDropDataConsumer, }); #endregion #region T R A S H // Data Consumer TrashConsumer trashConsumer = new TrashConsumer(new string[] { "TabItemObject", "TreeViewItemObject", "ListBoxItemObject", "CanvasTextBlockObject", "CanvasRectangleObject", "CanvasButtonObject", "ToolbarButtonObject", }); // Drop Manager DropManager dropHelperListBoxItemTrash = new DropManager(this.trash, trashConsumer); #endregion #region C A N V A S // Data Providers/Consumers CanvasDataProvider<Canvas, TextBlock> canvasTextBlockDataProvider = new CanvasDataProvider<Canvas, TextBlock>("CanvasTextBlockObject"); CanvasDataConsumer<Canvas, TextBlock> canvasTextBlockDataConsumer = new CanvasDataConsumer<Canvas, TextBlock>(new string[] { "CanvasTextBlockObject" }); CanvasDataProvider<Canvas, Rectangle> canvasRectangleDataProvider = new CanvasDataProvider<Canvas, Rectangle>("CanvasRectangleObject"); CanvasDataConsumer<Canvas, Rectangle> canvasRectangleDataConsumer = new CanvasDataConsumer<Canvas, Rectangle>(new string[] { "CanvasRectangleObject" }); CanvasDataProvider<Canvas, Button> canvasButtonDataProvider = new CanvasDataProvider<Canvas, Button>("CanvasButtonObject"); CanvasDataConsumer<Canvas, Button> canvasButtonDataConsumer = new CanvasDataConsumer<Canvas, Button>(new string[] { "CanvasButtonObject" }); // Data Consumer of Toolbar Buttons ToolbarButtonToCanvasButton<ToolBar, Button> toolbarButtonToCanvasButton = new ToolbarButtonToCanvasButton<ToolBar, Button>(new string[] { "ToolbarButtonObject" }); // Data consumer of System.Strings (creates a TextBlock) StringToCanvasTextBlock systemStringToCanvasTextBlock = new StringToCanvasTextBlock(new string[] { "System.String" }); // Drag Managers DragManager dragHelperCanvas0 = new DragManager(this.canvas0, new IDataProvider[] { canvasTextBlockDataProvider, canvasRectangleDataProvider, canvasButtonDataProvider, }); DragManager dragHelperCanvas1 = new DragManager(this.canvas1, new IDataProvider[] { canvasTextBlockDataProvider, canvasRectangleDataProvider, canvasButtonDataProvider, }); // Drop Managers DropManager dropHelperCanvas0 = new DropManager(this.canvas0, new IDataConsumer[] { canvasTextBlockDataConsumer, canvasRectangleDataConsumer, canvasButtonDataConsumer, toolbarButtonToCanvasButton, systemStringToCanvasTextBlock, }); DropManager dropHelperCanvas1 = new DropManager(this.canvas1, new IDataConsumer[] { canvasTextBlockDataConsumer, canvasRectangleDataConsumer, canvasButtonDataConsumer, toolbarButtonToCanvasButton, systemStringToCanvasTextBlock, }); #endregion #region T O O L B A R // Data Provider ToolBarDataProvider<ToolBar, Button> toolBarButtonDataProvider = new ToolBarDataProvider<ToolBar, Button>("ToolbarButtonObject"); // Data Consumer ToolBarDataConsumer<ToolBar, Button> toolBarButtonDataConsumer = new ToolBarDataConsumer<ToolBar, Button>(new string[] { "ToolbarButtonObject" }); // Data Consumer of Canvas Buttons CanvasButtonToToolbarButton<Canvas, Button> canvasButtonToToolbarButton = new CanvasButtonToToolbarButton<Canvas, Button>(new string[] { "CanvasButtonObject" }); // Drag Managers DragManager dragHelperToolBar0 = new DragManager(this.toolBar0, new IDataProvider[] { toolBarButtonDataProvider, }); DragManager dragHelperToolBar1 = new DragManager(this.toolBar1, new IDataProvider[] { toolBarButtonDataProvider, }); // Drop Managers DropManager dropHelperToolBar0 = new DropManager(this.toolBar0, new IDataConsumer[] { toolBarButtonDataConsumer, canvasButtonToToolbarButton, }); DropManager dropHelperToolBar1 = new DropManager(this.toolBar1, new IDataConsumer[] { toolBarButtonDataConsumer, canvasButtonToToolbarButton, }); #endregion }