So I am using MVVM light to develop a UWP application and I would like to place an AppBarButton in each item in a ListView. My code for the item template is below:
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding title}" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Text="{Binding uniqueID}" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<StackPanel Grid.Column="1" Grid.RowSpan="2" Width="40" Padding="0,4">
<AppBarButton Icon="Delete" IsCompact="True" Background="Red" Width="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ie:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="Click">
<ic:InvokeCommandAction Command="{Binding DataContext.DeleteItem, ElementName=page}" CommandParameter="{Binding}"/>
</ic:EventTriggerBehavior>
</ie:Interaction.Behaviors>
</AppBarButton>
</StackPanel>
</Grid>
</DataTemplate>
I did this same Event Trigger binding to another AppBarButton earlier in the page that was not inside a ListView and it worked perfectly fine. I have set up the referenced command the same way I set up the earlier one. The DataContext for the page is set correctly and I have verified that elsewhere by binding to it on other objects. For using this format to do this, I am referencing: Mvvm Light UWP Index Of Listitem When Button In ListItem Is Pressed
My problem is that when I have the below part uncommented, I get the below error from visual studio.
<ie:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="Click">
<ic:InvokeCommandAction Command="{Binding DataContext.DeleteItem, ElementName=page}" CommandParameter="{Binding}"/>
</ic:EventTriggerBehavior>
</ie:Interaction.Behaviors>
Collection property '__implicit_items' is null.
Does anybody have any ideas what I am doing wrong?
Thanks so much!!