Browse Source

Hack selecting controls when switching tree.

pull/4029/head
Steven Kirk 6 years ago
parent
commit
0d120fc115
  1. 17
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/MainViewModel.cs
  2. 2
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs

17
src/Avalonia.Diagnostics/Diagnostics/ViewModels/MainViewModel.cs

@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Diagnostics.Models;
using Avalonia.Input;
using Avalonia.Threading;
namespace Avalonia.Diagnostics.ViewModels
{
@ -49,7 +50,21 @@ namespace Avalonia.Diagnostics.ViewModels
value is TreePageViewModel newTree &&
oldTree?.SelectedNode?.Visual is IControl control)
{
newTree.SelectControl(control);
// HACK: We want to select the currently selected control in the new tree, but
// to select nested nodes in TreeView, currently the TreeView has to be able to
// expand the parent nodes. Because at this point the TreeView isn't visible,
// this will fail unless we schedule the selection to run after layout.
DispatcherTimer.RunOnce(
() =>
{
try
{
newTree.SelectControl(control);
}
catch { }
},
TimeSpan.FromMilliseconds(0),
DispatcherPriority.ApplicationIdle);
}
RaiseAndSetIfChanged(ref _content, value);

2
src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs

@ -95,8 +95,8 @@ namespace Avalonia.Diagnostics.ViewModels
if (node != null)
{
Selection.SelectedIndex = node.Index;
ExpandNode(node.Parent);
Selection.SelectedIndex = node.Index;
}
}

Loading…
Cancel
Save