我可以禁止显示"CanExecute"吗?在MVVM模式中调用 [英] Can I suppress the "CanExecute" call within the MVVM pattern

查看:114
本文介绍了我可以禁止显示"CanExecute"吗?在MVVM模式中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF和MVVM模式处理树结构.首先创建20个根节点,然后在单击每个节点时延迟加载子节点.例如...如果我有以下内容:

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

在运行时加载级别1、2和3.在单击它们各自的父级之前,将不会加载级别1.1、3.1和3.2.低于1.1等的级别通过单击其父级以相同的方式加载.

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.

我的问题是,当我单击级别1.1加载其子级时,将检查"CanExecute"方法的级别1.1以及级别1.1的每个子级的所有根级别项.如果有很多孩子,这会浪费大量时间.

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.

我的问题是,我可以某种方式抑制对"CanExecute"的调用吗?我不需要将其称为这些子级别,并且我想绕过它.我对MVVM框架非常陌生,因此不确定是否可以实现.

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.

推荐答案

如果在视图模型中使用Prism(WPF和SilverLight的复合应用程序指南)"DelegateCommand",则您必须在需要时显式调用command.RaiseCanExecuteChanged可以执行调用.

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.

这篇关于我可以禁止显示"CanExecute"吗?在MVVM模式中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆