//xaml <ListBox x:Name="lbx" SelectedIndex="0" ItemsSource="{Binding BooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VirtualizingPanel.IsContainerVirtualizable="True" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.ScrollUnit="Item" VirtualizingPanel.VirtualizationMode="Recycling"> <behavior:Interaction.Triggers> <behavior:EventTrigger EventName="SelectionChanged"> <behavior:InvokeCommandAction Command="{Binding SelectionChangedCmd}" PassEventArgsToCommand="True"/> </behavior:EventTrigger> </behavior:Interaction.Triggers> </ListBox> //cs private void InitCmds() { SelectionChangedCmd = new DelCmd(SelectionChangedCmdExecuted); } private void SelectionChangedCmdExecuted(object obj) { if(obj!=null) { var eventArgs = obj as SelectionChangedEventArgs; if(eventArgs!=null && eventArgs.AddedItems!=null && eventArgs.AddedItems.Count>0) { var bk = eventArgs.AddedItems[0] as Book; if(bk!=null) { ImgTitle = bk.Name; } } } }
标签:AddedItems,obj,eventArgs,bk,private,PassEventArgsToCommand,WPF,null,InvokeCommnd From: https://www.cnblogs.com/Fred1987/p/18422156