SearchPanel.xaml_1121

 

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;
using System.Collections.ObjectModel;
using System.Windows.Browser;

namespace ComputerDropDragControl
{
    /// <summary>
    /// “查询界面”
    /// 创建人:吴兆娟
    /// 创建时间:2011-11-1
    /// </summary>
    public partial class SearchPanel : UserControl
    {
        #region <<页面加载>>

        /// <summary>
        /// 页面加载
        /// </summary>
        public SearchPanel()
        {
            InitializeComponent();

            //初始化表单
            InitForm();

            //加载数据
            LoadData();
        }

        /// <summary>
        /// 初始化表单
        /// </summary>
        private void InitForm()
        {
            StaticClass.SearchPanelScroll = listComputer;

            double browseWidth = Application.Current.Host.Content.ActualWidth;//SilverLight控件所在浏览器确定的宽度
            double browseHeight = Application.Current.Host.Content.ActualHeight;

            double width = browseWidth;
            double height = browseHeight;
            if (!Application.Current.IsRunningOutOfBrowser)//指示是否从浏览器外状态启动
            {
                //获取浏览器分辨率信息
                ScriptObject screen = (ScriptObject)HtmlPage.Window.GetProperty("screen");
                width = (double)screen.GetProperty("width");
                height = (double)screen.GetProperty("height");
            }
            //listComputer.Height = height - 25 * 3 - (10 + 20 + 25 + 10) - 38;
            listComputer.Height = browseHeight - 25 * 3 - (10 + 20 + 25 + 10) - 38;
        }

        #endregion

        #region <<控件事件>>

        #region <<拖拽相关事件>>

        /// <summary>
        /// “拖”事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listDrag_ItemDragStarting(object sender, ItemDragEventArgs e)
        {
            StaticClass.FromList = true;
            StaticClass.DragPanelList = (ListBoxDragDropTarget)sender;

            ListBox list = (ListBox)this.listDrag.Content;
            ListBoxItem selectItem = (ListBoxItem)list.SelectedItem;
            int index = (int)list.SelectedIndex;
            SelectListItem = selectItem;
            SelectIndex = index;
        }

        private void listDrag_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.listDrag.Content;
                        list.Items.Insert(SelectIndex, SelectListItem);
                    }
                }
            }
        }

        #endregion

        /// <summary>
        /// “查询”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            List<NodeFrameView> result = nList.ToList<NodeFrameView>();
            if (!string.IsNullOrEmpty(this.txtNodeName.Text))
            {
                result = (from nodeFrameView in nList
                          where nodeFrameView.NodeName.IndexOf(this.txtNodeName.Text.Trim()) > 0
                          select nodeFrameView).ToList<NodeFrameView>();
            }
            listComputer.Items.Clear();
            foreach (NodeFrameView item in result)
            {
                ListBoxItem li = new ListBoxItem();
                li.Content = item.NodeName;
                li.DataContext = item;
                listComputer.Items.Add(li);
            }
        }
        #endregion

        #region <<辅助方法>>

        public ObservableCollection<NodeFrameView> nList;

        private ObservableCollection<NodeFrameView> LoadData()
        {
            return nList = new ObservableCollection<NodeFrameView>
            {
                new NodeFrameView("n1","List设备一",2),
                new NodeFrameView("n2","List设备二",3),
                new NodeFrameView("n3","List设备三",3),

                new NodeFrameView("n4","List设备五",3),
                new NodeFrameView("n5","List设备六",2),
                new NodeFrameView("n6","List设备七",1),
                new NodeFrameView("n7","List设备八",2)
            };
        }

        #endregion


        public ListBoxItem SelectListItem { get; set; }

        public int SelectIndex { get; set; }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值