用wpf设计树状单选和多选功能_可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能)...

效果图如下:支持分组的单选框,复选框样式和MVVM下功能的实现。这是项目中一个快捷键功能的扩展。

1,准备工作:VS2015 (15对WPF的支持变得异常的好,调试模式下允许自动更改属性。),随VS发布的Blend,几个基础类:

1 public classRelayCommand : ICommand2 {3 #region Fields

4

5 readonly Action_executeAct;6 readonly Predicate_canExecutePre;7 private readonlyAction _execute;8

9 private readonly Func_canExecute;10 #endregion

11

12 #region Constructors

13

14 ///

15 ///Creates a new command that can always execute.16 ///

17 /// The execution logic.

18 public RelayCommand(Actionexecute)19 : this(execute, null)20 {21 }22

23 ///

24 ///Creates a new command.25 ///

26 /// The execution logic.

27 /// The execution status logic.

28 public RelayCommand(Action execute, PredicatecanExecute)29 {30 if (execute == null)31 {32 throw new ArgumentNullException("execute");33 }34

35 _executeAct =execute;36 _canExecutePre =canExecute;37 }38

39

40 ///

41 ///Initializes a new instance of the RelayCommand class that42 ///can always execute.43 ///

44 /// The execution logic.

45 /// If the execute argument is null.

46 publicRelayCommand(Action execute)47 : this(execute, null)48 {49 }50

51 ///

52 ///Initializes a new instance of the RelayCommand class.53 ///

54 /// The execution logic.

55 /// The execution status logic.

56 /// If the execute argument is null.

57 public RelayCommand(Action execute, FunccanExecute)58 {59 if (execute == null)60 {61 throw new ArgumentNullException("execute");62 }63

64 _execute =execute;65 _canExecute =canExecute;66 }67

68 #endregion

69

70 #region ICommand Members

71

72 public bool CanExecute(objectparameter)73 {74 if (parameter == null)75 {76 return _canExecute == null ? true: _canExecute();77 }78

79 return _canExecutePre == null ? true: _canExecutePre(parameter);80 }81

82 public eventEventHandler CanExecuteChanged83 {84 add { CommandManager.RequerySuggested +=value; }85 remove { CommandManager.RequerySuggested -=value; }86 }87

88 public void Execute(objectparameter)89 {90 if (!CanExecute(parameter))91 return;92 if (parameter == null)93 {94 if (_execute != null)95 _execute();96 return;97 }98 if (_executeAct != null)99 _executeAct(parameter);100

101 }102

103 #endregion

104 }

View Cod

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值