Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
Handle Click of Button in Unbound column
posted

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>

Parents
No Data
Reply
  • 600
    posted

    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. 

Children
No Data