Пример #1
0
 /// <summary>
 /// 将新的数据对象集合对应的TreeViewItem控件包装为可拖曳
 /// </summary>
 void wrapTreeViewItemForDrag(DevTypeCollection devCollection)
 {
     foreach (DevType dataCell in devCollection.DevTypeList)
     {
         //根据数据源对象获取UI控件
         TreeViewItem tvItem = treeView1.ItemContainerGenerator.ContainerFromItem(dataCell) as TreeViewItem;
         if (tvItem != null)
         {
             new CustomDragDropHelper(tvItem);//包装成可拖曳的控件
             //tvItem.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(tvItem_PreviewMouseLeftButtonDown);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 刷新树控件
        /// </summary>
        void refreshTreeView(DevTypeCollection devTypeC)
        {
            treeView1.DataContext = devTypeC.DevTypeList;
            treeView1.ItemsSource = devTypeC.DevTypeList;

            wrapTreeViewItemForDrag(devTypeC);
        }
Пример #3
0
        /// <summary>
        /// 在元素已布局、已呈现且可用于交互时发生的事件函数。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                bus.DeviceType[] deviceTypeArray = Application.Current.Properties["DeviceTypeArray"] as bus.DeviceType[];
                if (deviceTypeArray == null)
                    throw new ApplicationException("当前Application缓存查找不到设备类型类表");
                DevTypeCollection devTypeC = new DevTypeCollection();
                devTypeC.initFromDataBusDevTypeArray(deviceTypeArray);
                refreshTreeView(devTypeC);//初始化树拖曳功能

                this.initDropCanvas();//初始化显示面板:将该用户已经监控的设备的对应图标放置在面板上
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
Пример #4
0
 /// <summary>
 /// 刷新所有数据
 /// </summary>
 public void refreshData()
 {
     string userID = Application.Current.Properties["userID"] as string;
     bus.DataBusServiceClient dataBusServiceClient = new bus.DataBusServiceClient();
     try
     {
         DataBus dataBus1 = new DataBus();
         dataBus1.fillDataBusByRemoteService(dataBusServiceClient,userID);
         //this.dataBus = dataBus1;
         Application.Current.Properties["DataBus"] = dataBus1;
         bus.DeviceType[] deviceTypeArray=dataBusServiceClient.QueryAllDeviceTypeInfo();
         Application.Current.Properties["DeviceTypeArray"] = deviceTypeArray;
         DevTypeCollection devTypeC=new DevTypeCollection();
         devTypeC.initFromDataBusDevTypeArray(deviceTypeArray);
         refreshTreeView(devTypeC);
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message);
         return;
     }
     finally
     {
         if (dataBusServiceClient != null)
             dataBusServiceClient.Close();
         dataBusServiceClient = null;
     }
 }