我正在使用堆棧面板來顯示列表框項目,但是當我決定將其更改爲虛擬化項目時,有時選定項目爲空。下面是我用調用選定項命令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>
如果我關掉虛擬化,這個問題不會發生。我怎樣才能防止它返回一個空項目?