将Interaction.Triggers设置为ListBoxItem
我已将Interaction.Triggers设置为ListBox,并在发生’SelectionChanged’事件时执行相应的TargetedTriggerAction,如下所示。
但我的要求是我需要将Interaction.Triggers设置为ListBoxItem的’PreviewMouseDown’事件(注意:ListBox通过ItemsSource填充)
你可以尝试这样的事情:
你可以在ListBoxItem上做PreviewMouseDown事件
private void ItemOnPreviewMouseDown( object sender, MouseButtonEventArgs e) { ((ListBoxItem) sender).IsSelected = true; }
您可以在不使用Interactivity.dll进行事件处理的情况下执行相同操作。