command in datagrid not works

Topics: Prism v4 - Silverlight 4
Jan 17, 2011 at 4:56 AM
Edited Jan 18, 2011 at 7:32 AM

There is a datagrid with a template column


                    <data:DataGridTemplateColumn Width="180" CanUserSort="False">
                                    <HyperlinkButton Content="View" Command="{Binding Path=DataContext.LinkButtonClickCommand,ElementName=LayoutRoot}" Style="{StaticResource GridHyperLink}"/>                                    


the DataContext is a ViewModel , and the LinkButtonClickCommand is a DelegateCommand

anyone help me why nothing happen when click the HyperlinkButton, Thanks!

Jan 17, 2011 at 5:57 PM


The reason your HyperLink button command is not working could be that you are setting your Command Binding incorrectly. You might find the following resources useful to achieve alternative ways of binding a command from within a DataTemplate:

Also you might check your view model’s code to check if you are instantiating correctly your delegate command. You can read more about how to achieve this on Prism´s documentation, Chapter 5 Implementing MVVM Pattern, specifically the Commands section. 

Since DelegateCommands inherits from DelegateCommandBase, that implements ICommand interface, you could try replacing the DelegateCommand for a simpler implementation of ICommand, so as to make sure that the issue doesn’t come specifically from the DelegateCommand. If you find that when using that implementation you experience the same problem, you could share your concern on the Silverlight Forum, where you might find better support around Silverlight specific problems.

I hope you find this information useful.


Miguel Bronzovic


Jan 18, 2011 at 7:31 AM
Edited Jan 18, 2011 at 7:32 AM


finally resolved by adding ViewModel as Resource. 

        public ProductList(ProductListViewModel viewModel)
            this.DataContext = viewModel;
            this.Resources.Add("ViewModel", viewModel);

and set HyperlinkButton's Command={Binding EditCommand, Source={StaticResource ViewModel}}


Nov 3, 2011 at 4:16 PM


You might find the following blog post useful, which explores one possible way to achieve this scenario using Prism's ObservableObject<T> class:

Prism: Binding to commands from inside DataTemplates

I hope you find this helpful.

Guido Leandro Maliandi

Nov 4, 2011 at 2:34 AM


For dynamic take a look at this .

Nov 4, 2011 at 2:35 AM

I was found there are a few way to do that.