我有一個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
}
如何將事件處理程序分配給ComboBox? – DHN 2013-03-20 13:35:00
@DHN它被分配到ComboBoxItem - 'item.MouseEnter + = item_MouseEnter;' – WPF 2013-03-20 13:36:03
他做了'item.MouseEnter + = item_MouseEnter;' – 2013-03-20 13:36:37