Browse Source

Allow DevTools to inspect popup visual trees.

pull/58/head
Steven Kirk 11 years ago
parent
commit
2c066f0f5d
  1. 1
      Perspex.Base/Perspex.Base.csproj
  2. 7
      Perspex.Controls/Popup.cs
  3. 2
      Perspex.Diagnostics/ViewModels/TreeNode.cs
  4. 12
      Perspex.Diagnostics/ViewModels/VisualTreeNode.cs
  5. 1
      Perspex.SceneGraph/Perspex.SceneGraph.csproj
  6. 22
      Perspex.SceneGraph/VisualTree/IVisualTreeHost.cs

1
Perspex.Base/Perspex.Base.csproj

@ -38,6 +38,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Binding.cs" /> <Compile Include="Binding.cs" />
<Compile Include="Diagnostics\PerspexObjectExtensions.cs" /> <Compile Include="Diagnostics\PerspexObjectExtensions.cs" />
<Compile Include="PerspexProperty`1.cs" />
<Compile Include="PriorityBindingEntry.cs" /> <Compile Include="PriorityBindingEntry.cs" />
<Compile Include="Collections\IPerspexList.cs" /> <Compile Include="Collections\IPerspexList.cs" />
<Compile Include="Collections\PerspexReadOnlyListView.cs" /> <Compile Include="Collections\PerspexReadOnlyListView.cs" />

7
Perspex.Controls/Popup.cs

@ -12,7 +12,7 @@ namespace Perspex.Controls
using Perspex.Rendering; using Perspex.Rendering;
using Perspex.VisualTree; using Perspex.VisualTree;
public class Popup : Control, ILogical public class Popup : Control, ILogical, IVisualTreeHost
{ {
public static readonly PerspexProperty<Control> ChildProperty = public static readonly PerspexProperty<Control> ChildProperty =
PerspexProperty.Register<Popup, Control>("Child"); PerspexProperty.Register<Popup, Control>("Child");
@ -80,6 +80,11 @@ namespace Perspex.Controls
get { return this.logicalChild; } get { return this.logicalChild; }
} }
IVisual IVisualTreeHost.Root
{
get { return this.popupRoot; }
}
public void Open() public void Open()
{ {
if (this.popupRoot == null) if (this.popupRoot == null)

2
Perspex.Diagnostics/ViewModels/TreeNode.cs

@ -36,7 +36,7 @@ namespace Perspex.Diagnostics.ViewModels
}); });
} }
public IReactiveDerivedList<TreeNode> Children public IReadOnlyReactiveList<TreeNode> Children
{ {
get; get;
protected set; protected set;

12
Perspex.Diagnostics/ViewModels/VisualTreeNode.cs

@ -7,6 +7,7 @@
namespace Perspex.Diagnostics.ViewModels namespace Perspex.Diagnostics.ViewModels
{ {
using Perspex.Controls; using Perspex.Controls;
using Perspex.VisualTree;
using ReactiveUI; using ReactiveUI;
internal class VisualTreeNode : TreeNode internal class VisualTreeNode : TreeNode
@ -14,7 +15,16 @@ namespace Perspex.Diagnostics.ViewModels
public VisualTreeNode(IVisual visual) public VisualTreeNode(IVisual visual)
: base((Control)visual) : base((Control)visual)
{ {
this.Children = visual.VisualChildren.CreateDerivedCollection(x => new VisualTreeNode(x)); var host = visual as IVisualTreeHost;
if (host == null || host.Root == null)
{
this.Children = visual.VisualChildren.CreateDerivedCollection(x => new VisualTreeNode(x));
}
else
{
this.Children = new ReactiveList<VisualTreeNode>(new[] { new VisualTreeNode(host.Root) });
}
if (this.Control != null) if (this.Control != null)
{ {

1
Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -100,6 +100,7 @@
<Compile Include="Thickness.cs" /> <Compile Include="Thickness.cs" />
<Compile Include="Vector.cs" /> <Compile Include="Vector.cs" />
<Compile Include="Visual.cs" /> <Compile Include="Visual.cs" />
<Compile Include="VisualTree\IVisualTreeHost.cs" />
<Compile Include="VisualTree\TransformedBounds.cs" /> <Compile Include="VisualTree\TransformedBounds.cs" />
<Compile Include="VisualTree\BoundsTracker.cs" /> <Compile Include="VisualTree\BoundsTracker.cs" />
<Compile Include="VisualTree\VisualExtensions.cs" /> <Compile Include="VisualTree\VisualExtensions.cs" />

22
Perspex.SceneGraph/VisualTree/IVisualTreeHost.cs

@ -0,0 +1,22 @@
// -----------------------------------------------------------------------
// <copyright file="IVisualTreeHost.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.VisualTree
{
/// <summary>
/// Interface for controls that host their own separate visual tree, such as popups.
/// </summary>
public interface IVisualTreeHost
{
/// <summary>
/// Gets the root of the hosted visual tree.
/// </summary>
/// <value>
/// The root of the hosted visual tree.
/// </value>
IVisual Root { get; }
}
}
Loading…
Cancel
Save