EquipmentTreeView.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-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;
            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);
            }

        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"download microsoft.ui.xaml.2.7_7.2208.15002.0_x64__8wekyb3d8bbwe" 是一个文件名或者包名称,通常与 Microsoft 的 XAML 库有关。XAML 是一种用于创建用户界面的标记语言。如果您想要下载并安装这个文件或包,可以按照以下步骤进行操作: 1. 打开您的网络浏览器,并前往 Microsoft 官方网站,或者使用适当的软件分发渠道,如 Microsoft Store 或官方开发者网站。 2. 在搜索框或导航栏中输入 "download microsoft.ui.xaml.2.7_7.2208.15002.0_x64__8wekyb3d8bbwe",并按下 Enter 键。 3. 在搜索结果页面或者相关页面中,找到与您要下载的特定文件或包相关的链接或按钮。 4. 单击该链接或按钮以开始下载过程。 5. 您可能会被要求登录您的 Microsoft 账户(如果尚未登录),以便将下载与您的帐户关联。 6. 确定下载位置,并选择您想要将文件保存到的目录。 7. 单击 "保存" 或 "下载",开始将文件或包下载到您的计算机。 8. 下载完成后,导航到文件或包所在的目录,并双击它来运行安装程序。 9. 按照安装程序中的指示逐步进行安装过程。 10. 安装完成后,您将能够使用 microsoft.ui.xaml.2.7_7.2208.15002.0_x64__8wekyb3d8bbwe 提供的功能或功能集。 请注意,这些步骤可能因您使用的操作系统、浏览器或下载渠道的不同而有所变化。请确保仔细阅读和遵守相关网站或程序的下载和安装指南。如果您对此文件或包有任何疑问或困难,建议您寻求相关技术支持或咨询 Microsoft 官方支持渠道。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值