public ControlDetailsViewModel(TreePageViewModel treePage, IVisual control) { _control = control; TreePage = treePage; var properties = GetAvaloniaProperties(control) .Concat(GetClrProperties(control)) .OrderBy(x => x, PropertyComparer.Instance) .ThenBy(x => x.Name) .ToList(); _propertyIndex = properties.GroupBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToList()); var view = new DataGridCollectionView(properties); view.GroupDescriptions.Add(new DataGridPathGroupDescription(nameof(AvaloniaPropertyViewModel.Group))); view.Filter = FilterProperty; PropertiesView = view; if (control is INotifyPropertyChanged inpc) { inpc.PropertyChanged += ControlPropertyChanged; } if (control is AvaloniaObject ao) { ao.PropertyChanged += ControlPropertyChanged; } }
public DevToolsViewModel(IControl root) { _root = root; _logicalTree = new TreePageViewModel(LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(VisualTreeNode.Create(root)); this.WhenAnyValue(x => x.SelectedTab).Subscribe(index => { switch (index) { case 0: Content = _logicalTree; break; case 1: Content = _visualTree; break; } }); _focusedControl = KeyboardDevice.Instance .WhenAnyValue(x => x.FocusedElement) .Select(x => x?.GetType().Name) .ToProperty(this, x => x.FocusedControl); _pointerOverElement = root.GetObservable(TopLevel.PointerOverElementProperty) .Select(x => x?.GetType().Name) .ToProperty(this, x => x.PointerOverElement); }
public DevToolsViewModel(IControl root) { _logicalTree = new TreePageViewModel(LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(VisualTreeNode.Create(root)); this.WhenAnyValue(x => x.SelectedTab).Subscribe(index => { switch (index) { case 0: Content = _logicalTree; break; case 1: Content = _visualTree; break; } }); _focusedControl = KeyboardDevice.Instance .WhenAnyValue(x => x.FocusedElement) .Select(x => x?.GetType().Name) .ToProperty(this, x => x.FocusedControl); _pointerOverElement = root.GetObservable(TopLevel.PointerOverElementProperty) .Select(x => x?.GetType().Name) .ToProperty(this, x => x.PointerOverElement); }
public MainViewModel(AvaloniaObject root) { _root = root; _logicalTree = new TreePageViewModel(this, LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(this, VisualTreeNode.Create(root)); _events = new EventsPageViewModel(this); UpdateFocusedControl(); if (KeyboardDevice.Instance is not null) { KeyboardDevice.Instance.PropertyChanged += KeyboardPropertyChanged; } SelectedTab = 0; if (root is TopLevel topLevel) { _pointerOverSubscription = topLevel.GetObservable(TopLevel.PointerOverElementProperty) .Subscribe(x => PointerOverElement = x); } else { #nullable disable _pointerOverSubscription = InputManager.Instance.PreProcess .OfType <Input.Raw.RawPointerEventArgs>() .Subscribe(e => { PointerOverRoot = e.Root; PointerOverElement = e.Root.GetInputElementsAt(e.Position).FirstOrDefault(); }); #nullable restore }
public MainViewModel(TopLevel root) { _root = root; _logicalTree = new TreePageViewModel(this, LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(this, VisualTreeNode.Create(root)); _events = new EventsPageViewModel(root); UpdateFocusedControl(); KeyboardDevice.Instance.PropertyChanged += KeyboardPropertyChanged; SelectedTab = 0; _pointerOverSubscription = root.GetObservable(TopLevel.PointerOverElementProperty) .Subscribe(x => PointerOverElement = x?.GetType().Name); Console = new ConsoleViewModel(UpdateConsoleContext); }
public DevToolsViewModel(IControl root) { _logicalTree = new TreePageViewModel(LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(VisualTreeNode.Create(root)); UpdateFocusedControl(); KeyboardDevice.Instance.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(KeyboardDevice.Instance.FocusedElement)) { UpdateFocusedControl(); } }; root.GetObservable(TopLevel.PointerOverElementProperty) .Subscribe(x => PointerOverElement = x?.GetType().Name); }
public MainViewModel(IControl root) { _root = root; _logicalTree = new TreePageViewModel(LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(VisualTreeNode.Create(root)); _events = new EventsPageViewModel(root); UpdateFocusedControl(); KeyboardDevice.Instance.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(KeyboardDevice.Instance.FocusedElement)) { UpdateFocusedControl(); } }; SelectedTab = 0; root.GetObservable(TopLevel.PointerOverElementProperty) .Subscribe(x => PointerOverElement = x?.GetType().Name); Console = new ConsoleViewModel(UpdateConsoleContext); }
public ControlDetailsViewModel(TreePageViewModel treePage, IVisual control) { _control = control; TreePage = treePage; var properties = GetAvaloniaProperties(control) .Concat(GetClrProperties(control)) .OrderBy(x => x, PropertyComparer.Instance) .ThenBy(x => x.Name) .ToList(); _propertyIndex = properties.GroupBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToList()); var view = new DataGridCollectionView(properties); view.GroupDescriptions.Add(new DataGridPathGroupDescription(nameof(AvaloniaPropertyViewModel.Group))); view.Filter = FilterProperty; PropertiesView = view; Layout = new ControlLayoutViewModel(control); if (control is INotifyPropertyChanged inpc) { inpc.PropertyChanged += ControlPropertyChanged; } if (control is AvaloniaObject ao) { ao.PropertyChanged += ControlPropertyChanged; } AppliedStyles = new ObservableCollection <StyleViewModel>(); PseudoClasses = new ObservableCollection <PseudoClassViewModel>(); if (control is StyledElement styledElement) { styledElement.Classes.CollectionChanged += OnClassesChanged; var pseudoClassAttributes = styledElement.GetType().GetCustomAttributes <PseudoClassesAttribute>(true); foreach (var classAttribute in pseudoClassAttributes) { foreach (var className in classAttribute.PseudoClasses) { PseudoClasses.Add(new PseudoClassViewModel(className, styledElement)); } } var styleDiagnostics = styledElement.GetStyleDiagnostics(); foreach (var appliedStyle in styleDiagnostics.AppliedStyles) { var styleSource = appliedStyle.Source; var setters = new List <SetterViewModel>(); if (styleSource is Style style) { foreach (var setter in style.Setters) { if (setter is Setter regularSetter) { var setterValue = regularSetter.Value; var resourceInfo = GetResourceInfo(setterValue); SetterViewModel setterVm; if (resourceInfo.HasValue) { var resourceKey = resourceInfo.Value.resourceKey; var resourceValue = styledElement.FindResource(resourceKey); setterVm = new ResourceSetterViewModel(regularSetter.Property, resourceKey, resourceValue, resourceInfo.Value.isDynamic); } else { setterVm = new SetterViewModel(regularSetter.Property, setterValue); } setters.Add(setterVm); } } AppliedStyles.Add(new StyleViewModel(appliedStyle, style.Selector?.ToString() ?? "No selector", setters)); } } UpdateStyles(); } }