views:

528

answers:

2

im using the WPFToolkit's DataGrid and im trying to get an edit button working, here is the column:

<my:DataGridTemplateColumn>
                    <my:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Hyperlink   Command="{Binding EditVenueCommand}" >Edit</Hyperlink>


                            </TextBlock>
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellTemplate>
                </my:DataGridTemplateColumn>

and i am getting the following error:

BindingExpression path error: 'EditVenueCommand' property not found on 'object' ''Venue' (HashCode=18626439)'. BindingExpression:Path=EditVenueCommand; DataItem='Venue' (HashCode=18626439); target element is 'Hyperlink' (HashCode=32883419); target property is 'Command' (type 'ICommand')

the EditVenueCommand is fireing perfectly when it is outside the grid.

also, the reason i am using a DataGridTemplateColumn instead of a DataGridHyperlinkColumn is because i couldnt get that to work either :(

+1  A: 

What's happening in your code is that the binding is treating "EditVenueCommand" as a property that it should find on the datacontext of the data template.

You really shouldn't use a Binding to hook up a command anyway, just use specify the namespace+type+command field like so:

Command="myns:MyType.EditVenueCommand"

Where myns is mapped to your CLR namespace. For example:

<Window xmlns:myns="clr-namespace:MyNamespace;assembly=MyAssemblyName" ...
Drew Marsh
that gives: 'vm:VenueManagerViewModel.EditVenueCommand' cannot be assigned to property 'Command'. 'CommandValueSerializer' ValueSerializer cannot convert from 'System.String'.
aaron
Well that's odd, can you try adding {x:Static } around that?
Drew Marsh
that seemed to work, i had to make my ViewModel static which i dont really like but thanks for your help
aaron
Hmm... you should only have to have made the Command static. If it wasn't already, that might have been the problem in the first place. Either way, glad to hear you have it working.
Drew Marsh
A: 

Drew you have enlightened me so much, I had always been binding to my commands but with your solution everything is a lot more elegant thanks so much :) this should be writen on reference books or maybe it's already there!