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