Skip to content

Commit

Permalink
Work around crash during GUI "find" operation
Browse files Browse the repository at this point in the history
Repositioning a virtualized WPF TreeView control is hard.  This
doesn't fix the underlying problem, but does prevent the application
from exploding.

(issue #22)
  • Loading branch information
fadden committed Jun 30, 2024
1 parent d2a71ce commit f3d3870
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cp2_wpf/DirectoryTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ internal static void BringItemIntoView(TreeView treeView, DirectoryTreeItem item
}
var tvItem = containerControl.ItemContainerGenerator.ContainerFromItem(dtItem);
containerControl = (ItemsControl)tvItem;
Debug.Assert(containerControl != null || stack.Count == 0);
if (containerControl == null && stack.Count != 0) {
// This happens in weird circumstances, notably when the "find" feature
// is blowing up.
Debug.WriteLine("GLITCH while bringing TreeView item into view");
break;
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion cp2_wpf/WPFCommon/WPFExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ public static class VirtualizingPanelExtensions {
/// </summary>
public static void BringIndexIntoView_Public(this VirtualizingPanel virtPanel, int index) {
Debug.Assert(virtPanel != null);
BringIndexIntoViewMethodInfo.Invoke(virtPanel, new object[] { index });
try {
BringIndexIntoViewMethodInfo.Invoke(virtPanel, new object[] { index });
} catch (TargetInvocationException ex) {
Debug.WriteLine("BringIndexIntoView_Public GLITCH: " + ex);
}
}
}

Expand Down

0 comments on commit f3d3870

Please sign in to comment.