/// <summary> /// listBox右键菜单 /// </summary> private void RuleListBox_MouseUp(object sender, MouseEventArgs e) { RuleListBox.SelectedIndex = RuleListBox.IndexFromPoint(e.X, e.Y); if (RuleListBox.SelectedIndex == -1) { return; } if (e.Button == MouseButtons.Right) { contextMenuStrip.Show(RuleListBox, e.Location); } }
private void RuleListView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (DataContext == null) { return; } var binding = new Binding { Source = DataModel.Instance.CurrentWorkbook.Rules, Mode = BindingMode.OneWay }; RuleListBox.SetBinding(ItemsControl.ItemsSourceProperty, binding); }
/// <summary> /// listBox右键菜单 /// </summary> private void RuleListBox_MouseUp(object sender, MouseEventArgs e) { RuleListBox.SelectedIndex = RuleListBox.IndexFromPoint(e.X, e.Y); if (RuleListBox.SelectedIndex == -1) { return; } if (e.Button == MouseButtons.Right) { var strip = new ContextMenuStrip(); strip.Items.Add(i18N.Translate("Delete")); strip.Items[0].Click += deleteRule_Click; strip.Show(RuleListBox, e.Location); //鼠标右键按下弹出菜单 } }