CollaborationUtil.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using CollaborativePlatformMain.DFEntity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Media;
  9. namespace CollaborativePlatformMain.Util
  10. {
  11. /// <summary>
  12. ///
  13. /// <para>文件名(File Name): CollaborationUtil.cs</para>
  14. ///
  15. /// <para>描述(Description): 协同窗体后台工具类</para>
  16. ///
  17. /// <para>数据表(Tables): nothing</para>
  18. ///
  19. /// <para>作者(Author): Ou Rui Song</para>
  20. ///
  21. /// <para>日期(Create Date): 2024年4月20日15:24:29</para>
  22. ///
  23. /// 修改记录(Revision History):
  24. /// R1:
  25. /// 修改作者:
  26. /// 修改日期:
  27. /// 修改理由:
  28. ///
  29. /// </summary>
  30. public class CollaborationUtil
  31. {
  32. /// <summary>
  33. /// 获得指定元素的所有子元素
  34. /// </summary>
  35. /// <typeparam name="T"></typeparam>
  36. /// <param name="obj"></param>
  37. /// <returns></returns>
  38. public static List<T> GetChildObjects<T>(DependencyObject obj) where T : FrameworkElement
  39. {
  40. DependencyObject child = null;
  41. List<T> childList = new List<T>();
  42. for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
  43. {
  44. child = VisualTreeHelper.GetChild(obj, i);
  45. if (child is T)
  46. {
  47. childList.Add((T)child);
  48. }
  49. childList.AddRange(GetChildObjects<T>(child));
  50. }
  51. return childList;
  52. }
  53. /// <summary>
  54. /// 获取名字在集合中的下标
  55. /// </summary>
  56. /// <param name="name"></param>
  57. /// <param name="treeViews"></param>
  58. /// <returns></returns>
  59. public static int GetIndexByTreeView(string name, List<TreeViewBind> treeViews)
  60. {
  61. for (int i = 0; i < treeViews.Count; i++)
  62. {
  63. if (treeViews[i].Name.Equals(name))
  64. {
  65. return i;
  66. }
  67. }
  68. return -1;
  69. }
  70. }
  71. }