前台
<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="ComputerDropDragControl.Recyle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left">
<StackPanel Margin="20,10,0,0">
<toolkit:ListBoxDragDropTarget x:Name="RecylePanel" AllowDrop="True" HorizontalAlignment="Left"
Drop="RecylePanel_Drop">
<ListBox Width="50" Height="50" x:Name="handCar">
<ListBox.Background>
<ImageBrush ImageSource="Img/Recyle.png" Stretch="Uniform">
</ImageBrush>
</ListBox.Background>
</ListBox>
</toolkit:ListBoxDragDropTarget>
<TextBlock Text="回收站" Visibility="Collapsed"></TextBlock>
</StackPanel>
</Grid>
</UserControl>
后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace ComputerDropDragControl
{
/// <summary>
/// “回收站”
/// 创建人:吴兆娟
/// 创建时间:2011-11-4
/// </summary>
public partial class Recyle : UserControl
{
#region <<页面加载>>
/// <summary>
/// “页面加载”
/// </summary>
public Recyle()
{
InitializeComponent();
}
#endregion
#region <<控件事件>>
/// <summary>
/// “放”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RecylePanel_Drop(object sender, Microsoft.Windows.DragEventArgs e)
{
StaticClass.DropInRecyle = true;
StaticClass.DrogPanelList = (ListBoxDragDropTarget)sender;
//打开模态窗口填写信息
OpenChildWindow();
}
/// <summary>
/// “模态窗口关闭”时发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cr_Closed(object sender, EventArgs e)
{
CWInRack cr = (CWInRack)sender;
if (cr.DialogResult == false)
{
//“放”
Dictionary<string, object> dicDrag = GetDropDragPanelContentValues(StaticClass.DragPanel);
//合并单元格
MergeUnit(StaticClass.DragPanel, dicDrag);
}
if (cr.DialogResult == true)
{
//数据交互
}
}
#endregion
#region <<辅助方法>>
/// <summary>
/// 获取DropDragPanel中值信息
/// </summary>
/// <param name="panel"></param>
/// <returns></returns>
private Dictionary<string, object> GetDropDragPanelContentValues(PanelDragDropTarget panel)
{
Dictionary<string, object> dic = new Dictionary<string, object>();
StackPanel aimStack = (StackPanel)panel.Content;
#region<<偷藏的一些设备以及机架信息赋值>>
string computerFrame = ((TextBlock)aimStack.Children[0]).Text;
int rackUNo = int.Parse(((TextBlock)aimStack.Children[1]).Text);
string existComputer = ((TextBlock)aimStack.Children[2]).Text;
#endregion
dic.Add("FrameID", computerFrame);
dic.Add("RackUNo", rackUNo);
dic.Add("ExistComputer", existComputer);
return dic;
}
/// <summary>
/// “合并单元格”
/// </summary>
/// <param name="panel"></param>
private void MergeUnit(PanelDragDropTarget panel, Dictionary<string, object> dicDrop)
{
//StackPanel stackContent = (StackPanel)(StaticClass.DragPanel.Content);
//ComputerUnit cu = StaticClass.CUStatic;
//Grid fatherDropGrid = (Grid)(panel.Parent);
//int tempDropCount = (fatherDropGrid.Children.Count() + 1) / 2;
//PanelDragDropTarget dropPanelEnd = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"]) * 2];
//dropPanelEnd.AllowDrop = false;
//dropPanelEnd.SetValue(Grid.RowSpanProperty, cu.ReturnNodeFrameView.NodeSize);
//StackPanel stackDropEnd = (StackPanel)dropPanelEnd.Content;
//stackDropEnd.Height = 40 * cu.ReturnNodeFrameView.NodeSize;
//TextBlock tbDropFrame = (TextBlock)stackDropEnd.Children[0];
//for (int j = 1; j < cu.ReturnNodeFrameView.NodeSize; j++)
//{
// PanelDragDropTarget dropPanelTemp = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"] + j) * 2];
// dropPanelTemp.Visibility = Visibility.Collapsed;
// dropPanelTemp.AllowDrop = false;
// StackPanel stackTemp = (StackPanel)dropPanelTemp.Content;
// ((TextBlock)stackTemp.Children[2]).Text = "true";
//}
//#region <<修改偷藏值>>
//((TextBlock)stackDropEnd.Children[2]).Text = "true";
//#endregion
//stackDropEnd.Children.Add(cu);
}
/// <summary>
/// 打开模态窗口
/// </summary>
private void OpenChildWindow()
{
CWInRecyle cr = new CWInRecyle();
cr.OverlayOpacity = 0.1;
cr.Height = 300;
cr.Width = 500;
//cr.Content = tempFrame;
cr.Show();
//cr.Closed += new EventHandler(cr_Closed);
}
#endregion
}
}