Skip to content

Why can't I bind command in DataContext? #18362

Answered by tobyfirth
kyuranger asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@DoubleDBE
Comment options

@tobyfirth
Comment options

@tobyfirth
Comment options

@kyuranger
Comment options

Answer selected by kyuranger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants