EquipmentTreeView--1123
来源:互联网 发布:阿里云app学生专区 编辑:程序博客网 时间:2024/04/26 19:35
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-10-24
/// </summary>
public partial class EquipmentTreeView : UserControl
{
ObservableCollection<Equipment> eList;
#region <<加载事件>>
/// <summary>
/// 初始化“设备树”
/// </summary>
public EquipmentTreeView(UIElement uc)
{
InitializeComponent();
BackElement = uc;
LoadData();
//绑定树
BindTree("0", null);
//初始化界面
InitForm();
//订阅“选项发生变化”事件
equipmentTree.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(equipmentTree_SelectedItemChanged);
}
/// <summary>
/// 初始化界面
/// </summary>
private void InitForm()
{
StaticClass.EquipmentTreeViewScroll = scrollOne;
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");
}
//scrollOne.Height = height - 25 * 3 - 32;
scrollOne.Height = browseHeight - 25 * 3 - 32;
TreeViewItem temp = (TreeViewItem)equipmentTree.Items[0];
temp.IsSelected = true;
Equipment entity = (Equipment)temp.DataContext;
returnID = entity.ID;
//加载遮罩层相关
StackPanel stackMark = new StackPanel();
stackMark.Background = new SolidColorBrush(Colors.Black);
stackMark.Opacity = 0.5;
((Grid)StaticClass.UIRoot).Children.Insert(1, stackMark);
((Border)((StackPanel)StaticClass.ProgressBarStatic).Parent).Visibility = Visibility.Visible;
StaticClass.UISB.Begin();
BindControl(entity.IsRoom, entity.ID);
}
#endregion
#region <<控件事件>>
/// <summary>
/// “选项”发生变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void equipmentTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
//增加遮罩层
StackPanel stackMark = new StackPanel();
stackMark.Background = new SolidColorBrush(Colors.Black);
stackMark.Opacity = 0.5;
((Grid)StaticClass.UIRoot).Children.Insert(1, stackMark);
((Border)((StackPanel)StaticClass.ProgressBarStatic).Parent).Visibility = Visibility.Visible;
StaticClass.UISB.Begin();
//选项发生变化
TreeView tree = sender as TreeView;
TreeViewItem treeViewItem = tree.SelectedItem as TreeViewItem;
returnID = ((Equipment)treeViewItem.DataContext).ID;
BindControl(((Equipment)treeViewItem.DataContext).IsRoom, ((Equipment)treeViewItem.DataContext).ID);
}
#endregion
#region <<辅助方法>>
/// <summary>
/// 递归绑定树
/// </summary>
/// <param name="root"></param>
/// <param name="xmlDoc"></param>
private void BindTree(string parentID, TreeViewItem treeViewItem)
{
List<Equipment> result = (from equipmentEntity in eList
where equipmentEntity.ParentID == parentID
select equipmentEntity).ToList<Equipment>();
if (result.Count > 0)
{
foreach (Equipment equipment in result)
{
TreeViewItem temp = new TreeViewItem();
temp.IsExpanded = true;
temp.Header = equipment.Name;
temp.DataContext = equipment;
if (treeViewItem == null)
{
equipmentTree.Items.Add(temp);
}
else
{
treeViewItem.Items.Add(temp);
}
BindTree(equipment.ID, temp);
}
}
}
/// <summary>
/// “设备类”
/// </summary>
//private class Equipment
//{
// public Equipment() { }
// public Equipment(string id, string parentID, string name, string description, bool isRoom)
// {
// ID = id;
// ParentID = parentID;
// Name = name;
// Description = description;
// IsRoom = isRoom;
// }
// public string ID { get; set; }
// public string ParentID { get; set; }
// public string Name { get; set; }
// public string Description { get; set; }
// public bool IsRoom { get; set; }
//}
/// <summary>
///
/// </summary>
/// <returns></returns>
private ObservableCollection<Equipment> LoadData()
{
eList = new ObservableCollection<Equipment>{
new Equipment("1","0","园区机房","园区机房",true),
new Equipment("2","1","园区机房排一","园区机房排一",false),
new Equipment("3","1","园区机房排二","园区机房排二",false),
new Equipment("4","1","园区机房排三","园区机房排三",false),
new Equipment("5","0","市区机房","市区机房",true),
new Equipment("6","5","市区机房排一","市区机房排一",false),
new Equipment("7","5","市区机房排二","市区机房排二",false),
new Equipment("8","0","新区机房","新区机房",true),
new Equipment("9","8","新区机房排一","新区机房排一",false),
new Equipment("10","8","新区机房排二","新区机房排二",false),
new Equipment("11","8","新区机房排三","新区机房排三",false),
new Equipment("12","8","新区机房排四","新区机房排四",false)
};
return eList;
}
//备注
//http://www.cnblogs.com/daizhj/archive/2009/02/02/1372088.html
#endregion
private string returnID;
/// <summary>
/// 返回“选中项”的ID
/// </summary>
public string ReturnID
{
get
{
return returnID;
}
}
/// <summary>
/// 客户端与控件交互的控件
/// </summary>
public UIElement BackElement { get; set; }
public void BindControl(bool isRoom, string ID)
{
((StackPanel)BackElement).Children.Clear();
if (isRoom)
{
ComputerRoom a = new ComputerRoom(ID, BackElement);
((StackPanel)BackElement).Children.Add(a);
}
else
{
ComputerRack a = new ComputerRack(ID);
((StackPanel)BackElement).Children.Add(a);
}
}
}
}
- EquipmentTreeView--1123
- EquipmentTreeView.xaml
- EquipmentTreeView.xaml_1118
- EquipmentTreeView.xaml_1121
- 1123
- 1123
- ComputerRack----1123
- ComputerRoom----1123
- ural 1123
- 1123--Expressions
- ZOJ-1123
- 1123 练习
- 1123常识
- 1123:最小公倍数
- 杂记1123
- USTC 1123 Two Hospitals
- ZOJ 1123 Triangle Encapsulation
- URAL - 1123 Salary(水题)
- ubuntu下eclipse打开java文件,注释内容为乱码,解决方法
- YII Framework学习教程-YII的Model-Action和Models-2011-11-23
- 消灭编译警告(Warning)
- VS2005和Matlab2010b的联合编程的配置。
- 生产者与消费者问题
- EquipmentTreeView--1123
- 转载学习c + +反汇编-来自贡献者feixiaoxing
- 语义的需要
- YII Framework学习教程-YII的V-view的form-view script-2011-11-23
- 函数指针vs函数对象
- 《彻底搞定C指针》指针与数组名
- dns安装与配置,以及基本用法。
- window.open和window.showModalDialog使用
- jni java.lang.UnsatisfiedLinkError