首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏哲学驱动设计

    WPF Command CanExecute 的执行逻辑

    WPF 中命令的 CanExecute 执行逻辑,我一直觉得比较麻烦,画出来就清晰多了,备忘:

    1.1K60发布于 2018-01-29
  • 来自专栏walterlv - 吕毅的博客

    When WPF Commands update their CanExecute states?

    public class WalterlvCommand : ICommand { public bool SomeFlag { get; set; } bool ICommand.CanExecute

    36120编辑于 2023-10-22
  • 来自专栏加菲猫的VFP

    从零开始学习X#(八-完结)

    " CanExecute="PrintCommand_CanExecute" /> </Window.CommandBindings> 这个命令绑定集合为我们的每个命令命名,告诉我们事件触发时该怎么做 在这背后,我们添加了这些方法(我在WPF项目中使用C#,但我可以选择使用X#,因为这里的代码量很小,因此无关紧要): privatevoid NewCommand_CanExecute(object sender , CanExecuteRoutedEventArgs e) { e.CanExecute= true; } privatevoid NewCommand_Executed(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("New Task"); } privatevoid PrintCommand_CanExecute (object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } privatevoid PrintCommand_Executed

    81120发布于 2021-08-16
  • 来自专栏小黎子数据分析

    WPF自学入门(十一)WPF MVVM模式Command命令

    ICommand需要用户定义两个方法bool CanExecute和void Execute。第一个方法可以让我们来判断是否可以执行这个命令,第二个方法就是我们具体的命令。 67 { 68 69 } 70 71 public RelayCommand(Action execute, Func<Boolean> canExecute = canExecute; 82 83 } 84 85 #endregion 86 87 88 89 #region ICommand (Object parameter) 126 127 { 128 129 return _canExecute == null ? true : _canExecute(); 130 131 } 132 133 134 135 public void Execute(Object parameter

    4K22发布于 2019-08-26
  • 来自专栏哲学驱动设计

    WPF中ICommand接口 的一个设计问题

    event EventHandler CanExecuteChanged; bool CanExecute(object parameter); void Execute The command source can then query the command using the CanExecute method.     按照MSDN中的解释,当CanExecuteChanged事件发生时,ICommandSource会调用ICommand的CanExecute方法来检测是否可以执行命令。 因为CanExecuteChanged发生,使用者的第一感觉就是CanExecute从false变到true或者由true变到false了。    

    1.2K70发布于 2018-01-29
  • 来自专栏dino.c的专栏

    [UWP 自定义控件]了解模板化控件(7):支持Command

    在CanExecuteChanged的事件处理函数及CommandParameter的PropertyChangedCallback中,根据Command.CanExecute(CommandParameter = Command) && Command.CanExecute(CommandParameter)) { Command.Execute(CommandParameter ); } private void UpdateIsEnabled() { IsEnabled = (null == Command) || Command.CanExecute MenuItemSamplePage() { this.InitializeComponent(); var command = new DelegateCommand<object>(Click, CanExecute MessageDialog dialog = new MessageDialog(parameter.ToString()); dialog.ShowAsync(); } private bool CanExecute

    72430发布于 2019-01-18
  • 来自专栏林德熙的博客

    WPF 绑定命令在 MVVM 的 CanExecute 和 Execute 在按钮点击都没触发可能的原因

    定义一个简单的命令 public class Command : ICommand { /// <inheritdoc /> public bool CanExecute UIElement) sender).Focus); } 此时运行代码,点击文本,可以看到输出窗口输出 林德熙是逗比 然后点击文本,输入文字,然后点击按钮,可以发现按钮的命令没有触发 在命令的 CanExecute 打上断点,可以发现连 CanExecute 都没有进入 如果遇到了在按钮 MVVM 绑定命令,发现命令没有触发,同时 CanExecute 都没有进入,可以猜可能是命令没有初始化、命令没有绑对,还有可能是在过程出现焦点问题

    2.9K20编辑于 2022-08-04
  • 来自专栏博客园

    深入浅出话命令

    本例中,当CommandBinding捕捉到CanExecute就会调用cb_CanExecute方法。当捕捉到是Executed的时候,就调用cb_Execute事件。 第三,因为CanExecute事件的激发频率比较高,为了避免降低性能,在处理完毕之后建议将e.Handle设置为true。 第四,CommandBinding一定要设置在命令目标的外围控件上,不然无法捕捉CanExecute和Executed等路由事件。 --为窗体添加CommandBinding-->   <Window.CommandBindings>   <CommandBinding Command="New" CanExecute="CommandBinding_CanExecute (txtName.Text))       {           e.CanExecute = false;       }   else       {           e.CanExecute

    2.2K40发布于 2018-08-31
  • 来自专栏一路走一路失去也一路拥有

    WPF MVVM 模式下自写自用的窗口样式

    ">判断命令是否能够执行的方法</param> public Command(Action<object> execute, Func<object, bool> canExecute) { _execute = execute; _canExecute = canExecute; } / (object parameter) { if (_canExecute == null) return true; return _canExecute _execute = execute; _canExecute = canExecute; } /// <summary (object parameter) { if (_canExecute == null) return true; return _canExecute

    2.2K30编辑于 2022-09-01
  • 来自专栏DotNet NB && CloudNative

    C# WPF数据绑定方法以及重写数据模板后数据绑定

    ">判断命令是否能够执行的方法</param> 54 public Command(Action<object> execute, Func<object, bool> canExecute ) 55 { 56 _execute = execute; 57 _canExecute = canExecute; 58 (object parameter) 66 { 67 if (_canExecute == null) return true; 68 return _canExecute(parameter); 69 } 70 71 ///

    72 /// 执行命令 73 /// = null && CanExecute(parameter)) 78 { 79 _execute(parameter); 80

    2.6K40编辑于 2023-08-29
  • 来自专栏hbbliyong

    WPF命令(Command)介绍、命令和数据绑定集成应用

    中命令系统的基础是一个相对简单的ICommand的接口,代码如下: public interface ICommand { event EventHandler CanExecuteChanged; bool CanExecute (object parameter); void Execute(object parameter); }        CanExecute用于确定命令是否处于可执行的状态。 典型的,UI控件能使用CanExecute来启用或禁用自己。也就是说,在相关的命令从CanExecute中返回False的时候,按钮将变得不可用。       在被调用后关闭应用程序,代码如下: public class Exit : ICommand { event EventHandler CanExecuteChanged; public bool CanExecute 这个例子虽然有点微不足道,不过可以使用CanExecute方法轻松地完成类似的行为,并针对“坏”文件禁用这个命令。然而,这里最重要的一点是,可以返回任何命令。

    7K40发布于 2018-03-05
  • .NET WinForms + WPF 综合学习路线:从传统到现代的.NET桌面开发

    class RelayCommand : ICommand { private readonly Action _execute; private readonly Func<bool> _canExecute ; public RelayCommand(Action execute, Func<bool> canExecute = null) { _execute = execute; _canExecute = canExecute; } public bool CanExecute(object parameter) = > _canExecute?.

    77610编辑于 2025-11-14
  • 来自专栏技术之路

    wpf RoutedUICommand 绑定

    Window.CommandBindings> <CommandBinding Command="{StaticResource btnClick1}" CanExecute ="CommandBinding_CanExecute1" Executed="CommandBinding_Executed1"/> </Window.CommandBindings (object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } ="cb_CanExecute" Executed="myRoudedEvent" /> </Window.CommandBindings> <Grid> <Menu (object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; }

    1.4K90发布于 2018-01-31
  • 来自专栏技术之路

    Caliburn.Micro学习笔记(五)----协同IResult

    object Target; public DependencyObject View; public MethodInfo Method; public Func<bool> CanExecute CanExecute: 一个函数,如果操作可被调用、 虚假否则返回 true。 key index: 一个地方来存储/检索它可以对框架的扩展所使用的任何附加元数据。

    65580发布于 2018-01-31
  • 来自专栏dino.c的专栏

    [Windows] Prism 8.0 入门(上):Prism.Core

    implement logic } private bool CanSubmit(string parameter) { return true; } 通常 UI 会根据 ICommand 的 CanExecute CanExecute 返回 DelegateCommand 构造函数中的第二个参数 canExecuteMethod 的返回值。如果不传入这个参数,则 CanExecute 一直返回 True。 如果 CanExecute 的返回值有变化,可以调用 RaiseCanExecuteChanged 函数,它会触发 CanExecuteChanged 事件并通知 UI 元素重新判断绑定的 ICommand RaiseCanExecuteChanged,DelegateCommand 还可以用 ObservesProperty 和 ObservesCanExecute 两种形式监视属性,定于属性的 PropertyChanged 事件并改变 CanExecute

    2.8K60发布于 2020-12-08
  • 来自专栏一路走一路失去也一路拥有

    WPF TreeGrid MVVM 模式下自定义表格带展开缩放效果,并且可以获取点击行的数据

    ">判断命令是否能够执行的方法</param> public Command(Action<object> execute, Func<object, bool> canExecute) { _execute = execute; _canExecute = canExecute; } / (object parameter) { if (_canExecute == null) return true; return _canExecute _execute = execute; _canExecute = canExecute; } /// <summary (object parameter) { if (_canExecute == null) return true; return _canExecute

    7.2K30编辑于 2022-05-31
  • 来自专栏DotNet 致知

    WPF中的命令(Command)

    第一个成员是个事件处理器,从名字可以看出来该事件处理器关注于第二个成员,也就是当命令能否执行的状态出现改变时可以使用此事件通知到关注此命令执行状态的成员; 第三个成员也是个方法,命令的执行逻辑放在这个方法里边,当CanExecute isCanExec被设置为FALSE,所以命令终止执行,输出窗口无内容: 【命令参数CommandParameter】 如果命令仅仅是这样使用,那就太单调了,大家肯定注意到了Execute和CanExecute

    2.1K20发布于 2021-11-05
  • 来自专栏dino.c的专栏

    使用 MVVM Toolkit Source Generators

    用 source generators 就没这些烦恼了,命令的定义可以简化成这样: [ICommand(CanExecute = nameof(HasName))] private void Display 此外,还可以通过它的 CanExecute 属性指定将 ICommand 的 CanExecute 关联到对应的属性。

    1.6K30编辑于 2022-05-07
  • 来自专栏黄腾霄的博客

    EventTrigger原理浅谈

    系统,在System.WIndows.Interactivity.dll中 原理都很类似,重点是两个 提供了InvokeCommandAction类,可以通过EventTrigger触发Command的CanExecute = null && command.CanExecute(commandParameter)) { command.Execute

    85630发布于 2020-06-10
  • 来自专栏Niuery的技术日记

    WPF --- 非Button自定义控件实现点击功能

    = null && routedCmd.CanExecute(parameter, target)) { routedCmd.Execute(parameter, = null && command.CanExecute(parameter)) { command.Execute(parameter); } execute) { _execute = execute; } public bool CanExecute(object?

    1.3K10编辑于 2023-10-22
领券