-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The TreeView seems to have an adverse effect on command binding #17387
Comments
Should you add a converter in multibinding? |
At a guess a MultiBinding does not produce a ReadOnlyCollection or anything that inherits from that, so your CanCreateSlave() method is always returning false. |
@rabbitism @IanRawley If you don't add a Converter, the ReadOnlyCollection is passed when the CanCreateSlave method is called. The problem is that in 11.1.4, when I select different TreeItems, the CanCreateSlave method is called, but in 11.2.0, the CanCreateSlave method is never called. |
You need to annotate your CanExecute equivalent method with the property or properties that can trigger changes. It seems MultiBindings don't automatically trigger re-evaluations of CanExecute for method bound commands. Binding to a single Property does though. So the problem isn't TreeView, it's MultiBinding. |
I now understand that it is not a problem with TreeView, but a problem with MultiBinding or Command. Even if I don't use annotation, the Can method should be triggered because the properties have changed. |
I've figured out the problem here. When a MultiBinding doesn't have a converter, the associated MultiBindingExpressions simply publishes a wrapper ReadOnlyCollection around its internal values array. The collection itself isn't Observable, and never actually itself changes, so while the values contained have changed the list itself is the same. As a result, the Binding system just silently ignores it because from its point of view nothing has changed. |
This was introduced by #16219 |
@IanRawley I understand. Thank you very much for your answer. |
Describe the bug
When I upgraded from 11.1.4 to 11.2.0, the command binding on the button failed. The following sample code can reproduce the problem.
11.1.4 good
1.mp4
11.2.0 Have a problem
When "a" is selected, the button is still unavailable
2.mp4
To Reproduce
The following sample code can reproduce the problem.
Expected behavior
No response
Avalonia version
11.2.0
OS
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: