我在TreeViewItem
上升事件时遇到问题。我总是得到这个例外
无法将类型为“System.Windows.RoutedEventArgs”的对象强制转换为类型 'System.Windows.Input.MouseButtonEventArgs'
我的代码背后是异常。
private void LibraryTree_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
if (LibraryTree.SelectedItem == null) { return; }
TreeViewItem tvi = (TreeViewItem)LibraryTree.SelectedItem;
tvi.RaiseEvent(new RoutedEventArgs(TreeViewItem.MouseDoubleClickEvent));
}
}
答案 0 :(得分:1)
MouseDoubleClickEvent期望MouseButtonEventArgs如此引发事件:
tvi.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
{ RoutedEvent = TreeViewItem.MouseDoubleClickEvent });