我有一个 ComboBox,有许多 ComboBoxItems。当用户将鼠标悬停在 ComboBoxItem 上时,我想触发一个事件。这是我到目前为止尝试过的代码,但是事件没有触发 - 即当我放置断点时,没有输入事件。
private void cmbValue_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ComboBox cmb = sender as ComboBox;
cmb.Items.Clear();
//Iterates through all virtual tables
foreach (TableContainer table in listOpenUnjoinedTables)
{
ComboBoxItem item = new ComboBoxItem();
item.MouseEnter += item_MouseEnter;
if (table.IsVirtual == false)
{
item.Content = "[" + table.TableDescription + "]";
}
else
{
item.Content = "[" + table.View.Name + "]";
}
item.Tag = table;
cmb.Items.Add(item);
}
}
private void item_MouseEnter(object sender, MouseEventArgs e)
{
ComboBoxItem item = sender as ComboBoxItem;
//Do task
}