Exemple #1
0
 public DebugConsoleTestView()
 {
     this.InitializeComponent();
     this.CollapseReleaseBuildWarning();
     DC.ShowLog();
     DC.Expand();
 }
Exemple #2
0
        private async void InitializeTest()
        {
            _grids.Add(testPanel);
            await this.WaitForLoadedAsync();

            var random = new Random();
            var colors = ColorExtensions.GetNamedColors();

            for (int i = 0; i < 20; i++)
            {
                var panel = _grids[random.Next(0, _grids.Count)];

                if (panel.ActualWidth - 10 <= 10 ||
                    panel.ActualHeight - 10 <= 10)
                {
                    i--;
                    continue;
                }

                var border = new Border();
                border.HorizontalAlignment = HorizontalAlignment.Left;
                border.VerticalAlignment   = VerticalAlignment.Top;
                border.Width  = random.Next((int)(panel.ActualWidth / 2), (int)(panel.ActualWidth - 10));
                border.Height = random.Next((int)(panel.ActualHeight / 2), (int)(panel.ActualHeight - 10));
                border.Margin =
                    new Thickness(
                        random.Next(0, (int)(panel.ActualWidth - border.Width) + 1),
                        random.Next(0, (int)(panel.ActualHeight - border.Height) + 1),
                        0,
                        0);
                border.Background = new SolidColorBrush(colors[random.Next(colors.Count)]);
                var childGrid = new Grid {
                    VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch
                };
                _grids.Add(childGrid);
                border.Child = childGrid;
                panel.Children.Add(border);
                var tb =
                    new TextBlock
                {
                    Text = string.Format("Panel {0}", i + 1),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };
                childGrid.Children.Add(tb);
                await childGrid.WaitForNonZeroSizeAsync();
            }

            await DC.ShowVisualTreeAsync(_grids[random.Next(_grids.Count)]);

            DC.Expand();
        }
        internal async Task SelectElementUnderPointer(bool showDebugger = true)
        {
            var roots =
                VisualTreeHelper.GetOpenPopups(Window.Current)
                .Where(p => p.Child != null)
                .Select(p => p.Child)
                .Reverse()
                .ToList();

            roots.Add(VisualTreeHelperExtensions.GetRealWindowRoot());

            UIElement hoveredElement = null;

            foreach (var root in roots)
            {
                var hoveredElements = VisualTreeHelper.FindElementsInHostCoordinates(
                    _pointerPosition,
                    root);

                var hoveredElementCandidate = hoveredElements.FirstOrDefault();

                if (hoveredElementCandidate != null)
                {
                    if (hoveredElement == null)
                    {
                        hoveredElement = hoveredElementCandidate;
                    }

                    // If multiple popups are overlaid and possibly also overlay a non-popup
                    // - how to select the right root?
                    // Consider if the selected element is actually hoverable -
                    //   popups might have a canvas that will show as being in host coordinates
                    //   even though it's not necessarily hit test visible.

                    var control = hoveredElementCandidate as Control;
                    var panel   = hoveredElementCandidate as Panel;

                    if (control != null &&
                        control.Background == null ||
                        panel != null &&
                        panel.Background == null)
                    {
                        continue;
                    }

                    hoveredElement = hoveredElementCandidate;
                    break;
                }
            }

            if (hoveredElement != null)
            {
                await SelectItem(hoveredElement, true);
            }

            if (showDebugger)
            {
                DC.Show();
                DC.Expand();
            }
        }