I have a program developed in WPF using MVVM pattern. In this XAML code, I have a ListView with multiple columns, and one of them has a clickable button to dispel an action to the ViewModel. The problem is that in the ViewModel I need to know what was the row.
The ListView
already has SelectedItem
binding property, but as I am clicking the button and not the line itself, the line is not marked as selected.
Can anyone tell me another way to obtain the clicked row? Thanks!
Interaction namespace declaration:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
ListView code:
<ListView x:Name="AndroidDescriptionsList" HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="6"
Margin="0" VerticalAlignment="Top" ItemContainerStyle="{DynamicResource boList}"
SelectedItem="{Binding SelectedAndroidCountryDescription}" Grid.ColumnSpan="7">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource boListHeader}">
<GridViewColumn Header="" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="DeleteAndroidCountryDescriptionBtn" Style="{StaticResource foButton.Standard.IconsTransparent}" MinWidth="40" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding DataContext.DeleteAndroidCountryDescriptionBtn, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type origin:ProductCreateView}}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBlock TextWrapping="Wrap" Text="{x:Static TechUI:AppConstants+ICONS.Error}" Foreground="#CCE74C3C" FontSize="20" Margin="0" Grid.Row="1"/>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Country_Name}" Header="País" Width="150"/>
<GridViewColumn DisplayMemberBinding="{Binding Country_Short_Name}" Header="Abreviatura" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Description}" Header="Descrição" Width="500"/>
</GridView>
</ListView.View>
</ListView>