Skip to content

Command Binding of a button inside a DataGridTemplateColumn #9240

Answered by AndrewKeepCoding
xaberue asked this question in Q&A
Discussion options

You must be logged in to vote

Try the following methods:

A

  • x:Name your Page or Window, "Root" for example.
  • Use the name above to bind the command via the DataContext:
<Button Command="{Binding ElementName=Root, Path=DataContext.ViewSecretCommand}" .../>

B

  • For the AncestorType, target a control that is outside of the DataTemplates. I guess in your case, it's the ItemsControl.
  • Be specific with the AncestorLevel.
  • SecretsPageViewModel is in a DataContext. So, your binding should be:
<Button Command="{Binding DataContext.ViewSecretCommand, RelativeSource...}" .../>

Some links that might help:

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@xaberue
Comment options

@miloush
Comment options

@xaberue
Comment options

Answer selected by xaberue
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