HandCar.xaml_New

 

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; }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值