Can I suppress the “CanExecute” call within the MVVM pattern

走远了吗. 提交于 2019-12-25 04:56:13

问题


I am working with a tree structure using WPF and the MVVM pattern. I start out by creating 20 root nodes and lazy loading the child nodes as each node is clicked. So for instance ... if I have the following:

Level 1
    Level 1.1
Level 2
Level 3
    Level 3.1
    Level 3.2

Levels 1, 2 and 3 are loaded at run time. Levels 1.1, 3.1 and 3.2 would not be loaded until their respective parents are clicked. Levels below 1.1 etc. are loaded the same way, by clicking on their parent.

My issue is when I click on Level 1.1 to load its children, the "CanExecute" method is checked for Level 1.1 AND all root level items for each child of Level 1.1. This causes quite a bit of wasted time if there are numerous children.

My question is, can I somehow suppress the call to "CanExecute"? I have no need to call it as these sub-levels and I'd like to bypass it. I am very new to the MVVM framework so I'm not sure if this is even possible.


回答1:


If you use Prism(Composite Application Guidance for WPF and SilverLight) 'DelegateCommand' in your view model, you will have to explicitly call command.RaiseCanExecuteChanged whenever you want CanExecute to be called on it.



来源:https://stackoverflow.com/questions/3506283/can-i-suppress-the-canexecute-call-within-the-mvvm-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!