gpt4 book ai didi

c# - 将 Mvvm Light 更新到版本 5 后,我需要做哪些更改才能使 RelayCommand CanExecute() 工作?

转载 作者:太空狗 更新时间:2023-10-29 20:07:22 25 4
gpt4 key购买 nike

我将 Mvvm Light 更新到版本 5 并注意到 RelayCommand 停止工作。

问题似乎是 CanExecute() 没有被调用来验证。它只验证一次,就像加载窗口时一样。

这可能是最近更新的错误,还是我需要在 XAML 中更改某些内容?

更新前一切正常。我正在使用 WPF。

最佳答案

查看此 MVVM Light 5 issue :

WPF is the only XAML framework that uses the CommandManager to automagically raise the CanExecuteChanged event on ICommands. I never liked that approach, because of the "magic" part, but this is a "feature" of WPF and of course I have to support it. No question here.

In V5, I moved to portable class library for all the newest versions of the XAML frameworks, including WPF4.5. Unfortunately, there is no CommandManager in PCL, and I have to admit that I didn't realize that at first sight. So of course now the automagical part doesn't work anymore. Again, so sorry about that.

I am not expecting you to raise CanExecuteChanged everywhere now, not after using the CommandManager in your application, which is what the WPF team intended. So I will try to find a way to restore the CommandManager usage in the WPF4.5 version of the toolkit.

Definitely not looking for excuses ;) but hope that explaining why the issue arose helps to make sense of this. It's going to be my priority No. 1 until I find a way to solve this in the PCL version. In the meantime, like I mentioned before, I think that going back to V4.4.32.7 should fix that. Please let me know if it does not.

所以暂时推荐的解决方案是恢复到之前的版本。我做到了并且成功了。

我同意 CommandManager 正在施展“魔法”。一旦我在 CanExecute 条件下出现空引用异常,结果我得到了无休止的错误消息循环,就像 Windows Solitaire 中的纸牌一样。如果我开始一个新项目,我宁愿不使用这个“魔法”,但要更改现有的和已经部署的项目会非常痛苦。

关于c# - 将 Mvvm Light 更新到版本 5 后,我需要做哪些更改才能使 RelayCommand CanExecute() 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26306779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com