mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-09 08:16:41 +12:00
Add protection against DisconnectedItem as sender object in mouse event handlers
Workaround was added in early development stage already:1f985c53aa
However, it was meant to be no longer occurring, so detection was removed here:6ebfed5f78
3f09f40188
3153032110
Since it occurred again, we reintroduce this fix at least on all mouse events. This time, we check for the expected object type rather looking up the item in the list.
This commit is contained in:
parent
4bb533ea7c
commit
569722a5b0
|
@ -1146,14 +1146,18 @@ namespace SystemTrayMenu.UserInterface
|
|||
{
|
||||
if (!isShellContextMenuOpen)
|
||||
{
|
||||
CellMouseEnter?.Invoke((RowData)((ListViewItem)sender).Content);
|
||||
// "DisconnectedItem" protection
|
||||
if (((ListViewItem)sender).Content is RowData rowData)
|
||||
{
|
||||
CellMouseEnter?.Invoke(rowData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ListViewItem_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
var content = ((ListViewItem)sender).Content;
|
||||
if (content is RowData rowData)
|
||||
// "DisconnectedItem" protection
|
||||
if (((ListViewItem)sender).Content is RowData rowData)
|
||||
{
|
||||
rowData.IsClicked = false;
|
||||
countLeftMouseButtonClicked = 0;
|
||||
|
@ -1169,19 +1173,30 @@ namespace SystemTrayMenu.UserInterface
|
|||
}
|
||||
}
|
||||
|
||||
private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e) =>
|
||||
CellMouseDown?.Invoke((RowData)((ListViewItem)sender).Content);
|
||||
private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// "DisconnectedItem" protection
|
||||
if (((ListViewItem)sender).Content is RowData rowData)
|
||||
{
|
||||
CellMouseDown?.Invoke(rowData);
|
||||
}
|
||||
}
|
||||
|
||||
private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
RowData rowData = (RowData)((ListViewItem)sender).Content;
|
||||
// "DisconnectedItem" protection
|
||||
if (((ListViewItem)sender).Content is RowData rowData)
|
||||
{
|
||||
rowData.IsClicked = true;
|
||||
countLeftMouseButtonClicked = e.ClickCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void ListViewItem_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
RowData rowData = (RowData)((ListViewItem)sender).Content;
|
||||
// "DisconnectedItem" protection
|
||||
if (((ListViewItem)sender).Content is RowData rowData)
|
||||
{
|
||||
if (rowData.IsClicked)
|
||||
{
|
||||
// Same row has been called with PreviewMouseLeftButtonDown without leaving the item, so we can call it a "click".
|
||||
|
@ -1189,19 +1204,25 @@ namespace SystemTrayMenu.UserInterface
|
|||
rowData.OpenItem(countLeftMouseButtonClicked);
|
||||
}
|
||||
|
||||
countLeftMouseButtonClicked = 0;
|
||||
rowData.IsClicked = false;
|
||||
}
|
||||
|
||||
countLeftMouseButtonClicked = 0;
|
||||
}
|
||||
|
||||
private void ListViewItem_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// "DisconnectedItem" protection
|
||||
if (((ListViewItem)sender).Content is RowData rowData)
|
||||
{
|
||||
// At mouse location
|
||||
Point position = Mouse.GetPosition(this);
|
||||
position.Offset(Left, Top);
|
||||
|
||||
isShellContextMenuOpen = true;
|
||||
((RowData)((ListViewItem)sender).Content).OpenShellContextMenu(position);
|
||||
rowData.OpenShellContextMenu(position);
|
||||
isShellContextMenuOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue