-
There is a project in our company. We don’t know which version of Avalonia it was created from, but it has been continuously upgraded with the upgrade of Avalonia. Previously, the binding of Command in this project was similar to this:
ViewModel:
Recently, we upgraded this project to 11.2.5 and planned to add some new features (this project hasn't added new features for a long time). We added code similar to the above, but it prompted the following error: But what confuses me is that the code that has been compiled successfully before never has such an error. I thought there was something wrong with my code until I created a new Avalonia 11.2.5 project and added the above code to test it, and it prompted the same error. I suspect that a certain version of Avalonia was changed, which caused this error to occur, but we don't know which version it was changed. What I still don't understand is why the code that compiled successfully in the previous version of Avalonia did not prompt such an error. How can I bind the Command of DataContext in the latest version of Avalonia? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I don't know the specifics when using $parent, but you can set
If someone can tell me how to use |
Beta Was this translation helpful? Give feedback.
-
I don't think a binding like that works if you are using compiled bindings which you might have enabled? There was also a refactor to the binding code in 11.1 which might have changed something. Changing it to this should work though. <Button Command="{Binding $parent[Window].((VM:TestViewModel)DataContext).TestCommand}">
</Button> You could also do something like this as well. <Button Command="{Binding $parent[ItemsControl].((VM:TestViewModel)DataContext).TestCommand}">
</Button> The documentation here has some more information about how compiled bindings work. |
Beta Was this translation helpful? Give feedback.
I don't think a binding like that works if you are using compiled bindings which you might have enabled? There was also a refactor to the binding code in 11.1 which might have changed something.
Changing it to this should work though.
You could also do something like this as well.
The documentation here has some more information about how compiled bindings work.