使用WPF写界面,xml配置文件自定义命令,以最少代码构建出侧边栏菜单


1.命令


2.xaml


3.xaml后台代码


4.xml自定义命令配置文件


5.效果,超出界面能滚动



网友答: 牛啊 和尚sama

网友答:
uvyx 发表于 2025-7-18 18:39
当前上下文中不存在名称“Acap” "ForEach"

  1. //
  2. // 摘要:
  3. //     Enumerates for each in this collection.
  4. //
  5. // 参数:
  6. //   this:
  7. //     The @this to act on.
  8. //
  9. //   action:
  10. //     The action.
  11. //
  12. // 类型参数:
  13. //   T:
  14. //     Generic type parameter.
  15. //
  16. // 返回结果:
  17. //     An enumerator that allows foreach to be used to process for each in this collection.
  18. public static IEnumerable<T> ForEach<T>(this IEnumerable<T> @this, Action<T> action)
  19. {
  20.      T[] array = @this.ToArray();
  21.      T[] array2 = array;
  22.      foreach (T obj in array2)
  23.      {
  24.          action(obj);
  25.      }

  26.      return array;
  27. }

  28. //
  29. // 摘要:
  30. //     Enumerates for each in this collection.
  31. //
  32. // 参数:
  33. //   this:
  34. //     The @this to act on.
  35. //
  36. //   action:
  37. //     The action.
  38. //
  39. // 类型参数:
  40. //   T:
  41. //     Generic type parameter.
  42. //
  43. // 返回结果:
  44. //     An enumerator that allows foreach to be used to process for each in this collection.
  45. public static IEnumerable<T> ForEach<T>(this IEnumerable<T> @this, Action<T, int> action)
  46. {
  47.      T[] array = @this.ToArray();
  48.      for (int i = 0; i < array.Length; i++)
  49.      {
  50.          action(array, i);
  51.      }

  52.      return array;
  53. }


global using Acap = Autodesk.AutoCAD.ApplicationServices.Application;

global using Acaop = Autodesk.AutoCAD.ApplicationServices.Core.Application;





网友答: 本帖最后由 箭头_Row 于 2025-1-8 20:47 编辑
lxl304712346 发表于 2024-10-22 17:20
有附件吗,大佬

照著大佬給的代碼抄呀,就這個函數:FindVisualChilds  麼有,直接照著這個抄:

public static class VisualTreeHelperExtensions
{
    public static IEnumerable<T> FindVisualChilds<T>(this DependencyObject depObj)
        where T : DependencyObject
    {
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
            if (child is T tChild)
                yield return tChild;

            foreach (T foundChild in FindVisualChilds<T>(child))
                yield return foundChild;
        }
    }
}

网友答:

网友答: 和尚大佬牛逼!

网友答:
不错,很多人可以直接捡过去装逼了

网友答: 怎么用啊

网友答: 厉害了  和尚大佬

网友答: 人狠话不多(⊙o⊙)

网友答: 和尚全能的  啥都会

网友答: 牛人,不知道咋用

网友答: 可以发一个吗
  • 上一篇:侧边工具栏目源码分享(C#)VS2022【更新】
  • 下一篇:没有了