SolidWorks二次开发 CommandGroup,CommandTabBox,菜单详解

菜单的层级结构
两种菜单形式:
第一种 Toobar菜单条
在这里插入图片描述
CommandManager->CommandGroup->CommandItem

 commandGroup = this.iCmdMgr.CreateCommandGroup2(this.int_0, this.cmdTitle, this.cmdToolTip, "", 5, true, ref num);

 commandGroup.LargeIconList = str + "\\IMG\\ToolbarLarge.bmp";
 commandGroup.LargeIconList = str + "\\IMG\\ToolbarLarge.bmp";
 commandGroup.LargeMainIcon = str + "\\IMG\\MainIconLarge.bmp";
 commandGroup.SmallMainIcon = str + "\\IMG\\MainIconSmall.bmp";
 int commandIndex = commandGroup.AddCommandItem2("批量自动出图", -1, "批量自动出图", "批量自动出图", 0, "KYGongNeng11", "EnableAll", 201, 3);
 nt commandIndex2 = commandGroup.AddCommandItem2("钣金转CAD", -1, "钣金转DWGDXF", "钣金转CAD", 2, "KYGongNeng7", "EnableAll", 202, 3);
 //添加分割线
 commandGroup.AddSpacer2(-1, -1);
 commandGroup.HasToolbar = true;
 commandGroup.HasMenu = true;
 commandGroup.Activate();

第二种 CommandTab
在这里插入图片描述
-> CommandTab -> CommandTabBox

                    commandTab = this.iCmdMgr.AddCommandTab(documentType, this.cmdTitle);
                    CommandTabBox commandTabBox = commandTab.AddCommandTabBox();
                    commandTabBox.AddCommands(this.cmdIDs, array);
                    //添加隔断
                    commandTabBox = commandTab.AddSeparator(commandTabBox, this.cmdIDs[6]);
                    commandTabBox = commandTab.AddSeparator(commandTabBothis.cmdIDs[26]);
                    ```

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
以下是一个简单的RelayCommand实现,您可以在WPF MVVM模式中使用它来绑定按钮事件: ```csharp public class RelayCommand : ICommand { private readonly Action _execute; private readonly Func<bool> _canExecute; public RelayCommand(Action execute, Func<bool> canExecute = null) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true; public void Execute(object parameter) => _execute(); public void RaiseCanExecuteChanged() => CommandManager.InvalidateRequerySuggested(); } ``` 在上面的代码中,RelayCommand类实现了ICommand接口,包括CanExecuteChanged、CanExecute和Execute方法。其中CanExecuteChanged用于通知UI更新按钮状态,CanExecute返回一个bool值,用于判断按钮是否可用,Execute用于执行按钮的操作。 使用RelayCommand时,需要在ViewModel中声明一个RelayCommand类型的属性,并在构造函数中实例化该属性,例如: ```csharp public class MainViewModel : ViewModelBase { public RelayCommand SelectImageCommand { get; set; } public MainViewModel() { SelectImageCommand = new RelayCommand(SelectImage); } private void SelectImage() { // 添加选择图像的代码 } } ``` 然后在XAML中绑定该属性,例如: ```xml <Button Content="选择图像" Command="{Binding SelectImageCommand}" /> ``` 通过以上步骤,您可以在WPF MVVM模式中使用自己实现的RelayCommand来绑定按钮事件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三好学生~张旺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值