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-3
/// </summary>
public partial class HandCar : UserControl
{
#region <<页面加载>>
/// <summary>
/// 页面加载
/// </summary>
public HandCar()
{
InitializeComponent();
//加载数据
LoadData();
}
#endregion
#region <<控件事件>>
/// <summary>
/// “开始拖”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void handCar_ItemDragStarting(object sender, ItemDragEventArgs e)
{
StaticClass.FromList = true;
StaticClass.FromHandCar = true;
StaticClass.DragPanelList = (ListBoxDragDropTarget)sender;
ListBox list = (ListBox)this.handCarPanel.Content;
ListBoxItem selectItem = (ListBoxItem)list.SelectedItem;
int index = (int)list.SelectedIndex;
SelectListItem = selectItem;
SelectIndex = index;
}
/// <summary>
/// “放”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void handCar_Drop(object sender, Microsoft.Windows.DragEventArgs e)
{
StaticClass.DropInHandCar = true;
StaticClass.DrogPanelList = (ListBoxDragDropTarget)sender;
//“拖”
StackPanel stackDrag = (StackPanel)StaticClass.DragPanel.Content;
ComputerUnit Cu = (ComputerUnit)stackDrag.Children[3];
//“放”
ListBoxDragDropTarget DropPanel = (ListBoxDragDropTarget)sender;
ListBox lbDrop = (ListBox)DropPanel.Content;
ListBoxItem lbi = new ListBoxItem();
lbi.DataContext = Cu.ReturnNodeFrameView;
lbi.Content = Cu.ReturnNodeFrameView.NodeName;
//lbi.Name = "LbiName" + (StaticClass.HandCarList.Count + 1).ToString();
lbDrop.Items.Add(lbi);
//StaticClass.HandCarList.Add(lbi);//??
}
/// <summary>
/// “放好在目标后”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void handCar_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
{
if (StaticClass.DropPanel != null)
{
if (StaticClass.DropPanel.AllowDrop)
{
if (!StaticClass.ExistPlace)
{
((StackPanel)StaticClass.DropPanel.Content).Children.RemoveAt(3);
StaticClass.DropPanel.AllowDrop = true;
ListBox list = (ListBox)this.handCarPanel.Content;
list.Items.Insert(SelectIndex, SelectListItem);
}
}
}
}
#endregion
#region <<辅助方法>>
/// <summary>
/// “加载数据”
/// </summary>
private void LoadData()
{
//if (StaticClass.HandCarList != null)
//{
// foreach (ListBoxItem item in StaticClass.HandCarList)
// {
// ListBoxItem lbi = new ListBoxItem();
// lbi.Content = item.Content;
// lbi.DataContext = item.DataContext;
// lbi.Name = item.Name;
// this.handCar.Items.Add(lbi);
// }
//}
}
#endregion
public ListBoxItem SelectListItem { get; set; }
public int SelectIndex { get; set; }
}
}