I am using the MVVM Light toolkit and when I click on a button in a row's unbound column, I want to execute a command on the View's corresponding ViewModel passing the POCO in the row's DataContext as the command parameter.
This is what I have so far:
<igGrid:XamWebGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=ItemEntities}" > <igGrid:XamWebGrid.Columns> <!--Edit Column --> <igGrid:UnboundColumn Key="EditColumn"> <igGrid:UnboundColumn.ItemTemplate> <DataTemplate> <Button Content="Edit"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <cmd:EventToCommand Command="{Binding Mode=OneWay, Path=EditItemCommand}" CommandParameter="{Binding}"/> </i:EventTrigger> </i:Interaction.Triggers> </Button> </DataTemplate> </igGrid:UnboundColumn.ItemTemplate> </igGrid:UnboundColumn>
<igGrid:TextColumn Key="ItemId" HeaderText="ID" Width="55"/> <igGrid:TextColumn Key="Title" HeaderText="Title" Width="310"/> </igGrid:XamWebGrid.Columns>
</igGrid:XamWebGrid>
Hi,
I resolve this issue by creating an empty property in my "ViewModel" and adding a templatecolumn and adjusting behavior as a UnboundColumn:
<ig:TemplateColumn Key="Adicionar" IsFilterable="False" IsSortable="False" Width="Auto" HorizontalContentAlignment="Center"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <Button Content="+" Command="{Binding Path=AdicionarCommand}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn >
It is SL 4.0
Jaimir G.
So the DataContext of an UnbouncColumn is: an UnboundColumnDataContext
Which has the following properties that you can bind to: RowData, Value, and ColumnKey.
So in order to bind to your row's data, you would use the RowData property.
However, you won't be able to escape the bounds of that DataCOntext, so that means unless your Data has access to the View or the command is on your row's data, you won't be able get a handle on your EditItemCommand
In the future we could look at expanding what's available to the the UnboundColumnDataContext.
-SteveZ