Browse Source

Add focused control to devtools.

pull/58/head
Steven Kirk 11 years ago
parent
commit
5c5cfc641e
  1. 72
      Perspex.Diagnostics/DevTools.cs
  2. 11
      Perspex.Diagnostics/ViewModels/DevToolsViewModel.cs
  3. 25
      Perspex.Input/KeyboardDevice.cs

72
Perspex.Diagnostics/DevTools.cs

@ -64,48 +64,50 @@ namespace Perspex.Diagnostics
{
this.DataTemplates.Add(new ViewLocator<ReactiveObject>());
this.Content = new TabControl
this.Content = new Grid
{
Items = new[]
RowDefinitions = new RowDefinitions
{
new TabItem
new RowDefinition(new GridLength(1, GridUnitType.Star)),
new RowDefinition(GridLength.Auto),
},
Children = new Controls
{
new TabControl
{
Header = "Logical Tree",
[!TabItem.ContentProperty] = this.viewModel.WhenAnyValue(x => x.LogicalTree),
Items = new[]
{
new TabItem
{
Header = "Logical Tree",
[!TabItem.ContentProperty] = this.viewModel.WhenAnyValue(x => x.LogicalTree),
},
new TabItem
{
Header = "Visual Tree",
[!TabItem.ContentProperty] = this.viewModel.WhenAnyValue(x => x.VisualTree),
}
},
},
new TabItem
new StackPanel
{
Header = "Visual Tree",
[!TabItem.ContentProperty] = this.viewModel.WhenAnyValue(x => x.VisualTree),
Orientation = Orientation.Horizontal,
Gap = 4,
[Grid.RowProperty] = 1,
Children = new Controls
{
new TextBlock
{
Text = "Focused: "
},
new TextBlock
{
[!TextBlock.TextProperty] = this.viewModel.WhenAnyValue(x => x.FocusedControl).Select(x => x?.GetType().Name)
}
}
}
},
}
};
}
//private Control GetHeader(VisualTreeNode node)
//{
// var result = new StackPanel
// {
// Orientation = Orientation.Horizontal,
// Gap = 8,
// Children = new Controls
// {
// new TextBlock
// {
// Text = node.Type,
// FontStyle = node.IsInTemplate ? Media.FontStyle.Italic : Media.FontStyle.Normal,
// },
// new TextBlock
// {
// [!TextBlock.TextProperty] = node.WhenAnyValue(x => x.Classes),
// }
// }
// };
// result.PointerEnter += this.AddAdorner;
// result.PointerLeave += this.RemoveAdorner;
// return result;
//}
}
}

11
Perspex.Diagnostics/ViewModels/DevToolsViewModel.cs

@ -9,6 +9,7 @@ namespace Perspex.Diagnostics.ViewModels
using System;
using Perspex.Controls;
using ReactiveUI;
using Perspex.Input;
internal class DevToolsViewModel : ReactiveObject
{
@ -18,6 +19,8 @@ namespace Perspex.Diagnostics.ViewModels
private VisualTreeViewModel visualTree;
private ObservableAsPropertyHelper<IInputElement> focusedControl;
public DevToolsViewModel()
{
this.WhenAnyValue(x => x.Root).Subscribe(x =>
@ -25,6 +28,9 @@ namespace Perspex.Diagnostics.ViewModels
this.LogicalTree = new LogicalTreeViewModel(root);
this.VisualTree = new VisualTreeViewModel(root);
});
this.focusedControl = KeyboardDevice.Instance.WhenAnyValue(x => x.FocusedElement)
.ToProperty(this, x => x.FocusedControl);
}
public Control Root
@ -44,5 +50,10 @@ namespace Perspex.Diagnostics.ViewModels
get { return this.visualTree; }
private set { this.RaiseAndSetIfChanged(ref this.visualTree, value); }
}
public IInputElement FocusedControl
{
get { return this.focusedControl.Value; }
}
}
}

25
Perspex.Input/KeyboardDevice.cs

@ -7,14 +7,18 @@
namespace Perspex.Input
{
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Runtime.CompilerServices;
using Perspex.Input.Raw;
using Perspex.Interactivity;
using Splat;
public abstract class KeyboardDevice : IKeyboardDevice
public abstract class KeyboardDevice : IKeyboardDevice, INotifyPropertyChanged
{
private IInputElement focusedElement;
public KeyboardDevice()
{
this.InputManager.RawEventReceived
@ -23,6 +27,8 @@ namespace Perspex.Input
.Subscribe(this.ProcessRawEvent);
}
public event PropertyChangedEventHandler PropertyChanged;
public static IKeyboardDevice Instance
{
get { return Locator.Current.GetService<IKeyboardDevice>(); }
@ -40,8 +46,16 @@ namespace Perspex.Input
public IInputElement FocusedElement
{
get;
private set;
get
{
return this.focusedElement;
}
private set
{
this.focusedElement = value;
this.RaisePropertyChanged();
}
}
public abstract ModifierKeys Modifiers { get; }
@ -74,6 +88,11 @@ namespace Perspex.Input
}
}
protected void RaisePropertyChanged([CallerMemberName] string propertyName = "")
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void ProcessRawEvent(RawKeyEventArgs e)
{
IInputElement element = this.FocusedElement;

Loading…
Cancel
Save