使用WPF写界面,xml配置文件自定义命令,以最少代码构建出侧边栏菜单
1.命令
2.xaml
3.xaml后台代码
4.xml自定义命令配置文件
5.效果,超出界面能滚动
网友答: 牛啊 和尚sama网友答:

global using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
global using Acaop = Autodesk.AutoCAD.ApplicationServices.Core.Application;
网友答: 本帖最后由 箭头_Row 于 2025-1-8 20:47 编辑
照著大佬給的代碼抄呀,就這個函數: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⊙)网友答:
和尚全能的 啥都会网友答:
牛人,不知道咋用网友答:
可以发一个吗
1.命令
2.xaml
3.xaml后台代码
4.xml自定义命令配置文件
5.效果,超出界面能滚动
网友答: 牛啊 和尚sama网友答:
uvyx 发表于 2025-7-18 18:39
当前上下文中不存在名称“Acap” "ForEach"

- //
- // 摘要:
- // Enumerates for each in this collection.
- //
- // 参数:
- // this:
- // The @this to act on.
- //
- // action:
- // The action.
- //
- // 类型参数:
- // T:
- // Generic type parameter.
- //
- // 返回结果:
- // An enumerator that allows foreach to be used to process for each in this collection.
- public static IEnumerable<T> ForEach<T>(this IEnumerable<T> @this, Action<T> action)
- {
- T[] array = @this.ToArray();
- T[] array2 = array;
- foreach (T obj in array2)
- {
- action(obj);
- }
- return array;
- }
- //
- // 摘要:
- // Enumerates for each in this collection.
- //
- // 参数:
- // this:
- // The @this to act on.
- //
- // action:
- // The action.
- //
- // 类型参数:
- // T:
- // Generic type parameter.
- //
- // 返回结果:
- // An enumerator that allows foreach to be used to process for each in this collection.
- public static IEnumerable<T> ForEach<T>(this IEnumerable<T> @this, Action<T, int> action)
- {
- T[] array = @this.ToArray();
- for (int i = 0; i < array.Length; i++)
- {
- action(array, i);
- }
- return array;
- }
- }
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⊙)网友答:
和尚全能的 啥都会网友答:
牛人,不知道咋用网友答:
可以发一个吗