スタック パネルを使用してリストボックス アイテムを表示していましたが、仮想化パネルに変更すると、選択したアイテムが null になることがありました。選択した項目コマンドを呼び出すために使用していた DataTemplate の一部を次に示します。
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding IsSelected}" Value="True">
<i:InvokeCommandAction CommandParameter="{Binding}"
Command="{Binding DataContext.SelectItemCommand, RelativeSource={RelativeSource AncestorType={x:Type ListBox}, Mode=FindAncestor}}" />
</ei:DataTrigger>
</i:Interaction.Triggers>
リストボックスは次のとおりです。
<ListBox x:Name="_itemsListBox"
Grid.Row="1"
ScrollViewer.CanContentScroll="true"
ItemsSource="{Binding Items}"
IsSynchronizedWithCurrentItem="True"
SelectionMode="Single"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemTemplate="{StaticResource ListItemTemplate}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
仮想化をオフにすると、この問題は発生しません。nullアイテムを返さないようにするにはどうすればよいですか?