diff --git a/ILSpy/AssemblyTree/AssemblyListPane.xaml.cs b/ILSpy/AssemblyTree/AssemblyListPane.xaml.cs index af7b14a91..2e9844d23 100644 --- a/ILSpy/AssemblyTree/AssemblyListPane.xaml.cs +++ b/ILSpy/AssemblyTree/AssemblyListPane.xaml.cs @@ -23,6 +23,7 @@ using System.Windows.Threading; using ICSharpCode.ILSpy.ViewModels; using ICSharpCode.ILSpyX.TreeView; +using TomsToolbox.Wpf; using TomsToolbox.Wpf.Composition.AttributedModel; namespace ICSharpCode.ILSpy.AssemblyTree @@ -56,7 +57,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree var selected = model.SelectedItem; if (selected != null) { - this.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => { + this.BeginInvoke(DispatcherPriority.Background, () => { ScrollIntoView(selected); this.SelectedItem = selected; }); @@ -69,7 +70,8 @@ namespace ICSharpCode.ILSpy.AssemblyTree if (SelectedItem is SharpTreeNode selectedItem) { - FocusNode(selectedItem); + // defer focusing, so it does not interfere with selection via mouse click + this.BeginInvoke(() => FocusNode(selectedItem)); } else { diff --git a/ILSpy/AssemblyTree/AssemblyTreeModel.cs b/ILSpy/AssemblyTree/AssemblyTreeModel.cs index 3155b29b0..11df01390 100644 --- a/ILSpy/AssemblyTree/AssemblyTreeModel.cs +++ b/ILSpy/AssemblyTree/AssemblyTreeModel.cs @@ -640,6 +640,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree private void JumpToReference(object? sender, NavigateToReferenceEventArgs e) { JumpToReferenceAsync(e.Reference, e.InNewTabPage).HandleExceptions(); + IsActive = true; } /// diff --git a/ILSpy/Controls/TreeView/SharpTreeView.cs b/ILSpy/Controls/TreeView/SharpTreeView.cs index 4c99b4b45..6215f9bff 100644 --- a/ILSpy/Controls/TreeView/SharpTreeView.cs +++ b/ILSpy/Controls/TreeView/SharpTreeView.cs @@ -30,6 +30,8 @@ using System.Windows.Threading; using ICSharpCode.ILSpyX.TreeView; +using TomsToolbox.Wpf; + namespace ICSharpCode.ILSpy.Controls.TreeView { public class SharpTreeView : ListView @@ -396,9 +398,10 @@ namespace ICSharpCode.ILSpy.Controls.TreeView /// public void FocusNode(SharpTreeNode node) { - if (node == null) - throw new ArgumentNullException("node"); + ArgumentNullException.ThrowIfNull(node); + ScrollIntoView(node); + // WPF's ScrollIntoView() uses the same if/dispatcher construct, so we call OnFocusItem() after the item was brought into view. if (this.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) { @@ -406,7 +409,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView } else { - this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(this.OnFocusItem), node); + this.BeginInvoke(DispatcherPriority.Loaded, () => OnFocusItem(node)); } }