/// <summary>
        /// Total up the child layout slot rects of the StackPanel parent.
        /// </summary>
        /// <param name="Parent"></param>
        /// <returns></returns>
        public static Rect?GetUnionChildLayoutSlots(this StackPanel Parent)
        {
            Rect?unionRect = null;

            foreach (UIElement uiChild in Parent.Children)
            {
                if (uiChild is FrameworkElement)
                {
                    FrameworkElement fwChild = uiChild as FrameworkElement;
                    Rect             slot    = LayoutInformation.GetLayoutSlot(fwChild);
                    if (unionRect == null)
                    {
                        unionRect = slot;
                    }
                    else
                    {
                        Rect ur = unionRect.Value;
                        ur.Union(slot);
                        unionRect = ur;
//            unionRect.Value.Union(slot);
                    }
                }
            }
            return(unionRect);
        }
Exemplo n.º 2
0
        public void ArrangeTest()
        {
            Border b1 = new Border();

            b1.Background = new SolidColorBrush(Colors.Red);
            b1.Width      = 50;
            b1.Height     = 25;

            Border b2 = new Border();

            b2.Background = new SolidColorBrush(Colors.Blue);
            b2.Width      = 25;
            b2.Height     = 30;

            var stack = new StackPanel();

            stack.Children.Add(b1);
            stack.Children.Add(b2);

            stack.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

            Assert.AreEqual(new Size(50, 55), stack.DesiredSize, "stack desired");
            Assert.AreEqual(new Size(0, 0), new Size(stack.ActualWidth, stack.ActualHeight), "stack actual");

            stack.Arrange(new Rect(10, 10, stack.DesiredSize.Width, stack.DesiredSize.Height));

            Assert.AreEqual(new Size(50, 55), stack.DesiredSize, "stack desired1");
            Assert.AreEqual(new Size(50, 55), stack.RenderSize, "stack render1");
            Assert.AreEqual(new Rect(10, 10, 50, 55), LayoutInformation.GetLayoutSlot(stack), "stack slot");
        }
Exemplo n.º 3
0
        public void LayoutMarginTest()
        {
            Border b     = new Border();
            var    stack = new StackPanel();

            stack.Children.Add(CreateSlotItem());
            stack.Children.Add(CreateSlotItem());
            stack.Children.Add(CreateSlotItem());
            stack.HorizontalAlignment = HorizontalAlignment.Right;
            b.Width      = 50;
            b.Child      = stack;
            stack.Margin = new Thickness(10, 20, 0, 0);

            b.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            b.Arrange(new Rect(0, 0, b.DesiredSize.Width, b.DesiredSize.Height));

            Assert.AreEqual(new Rect(0, 0, 25, 33).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[0]).ToString());
            Assert.AreEqual(new Rect(0, 33, 25, 33).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[1]).ToString());
            Assert.AreEqual(new Rect(0, 66, 25, 33).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[2]).ToString());
            Assert.AreEqual(new Rect(0, 0, 50, 119).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack).ToString(), "stack");
            Assert.AreEqual(new Rect(0, 0, 50, 119).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)b).ToString(), "border");

            Assert.AreEqual(new Size(50, 119), b.DesiredSize);
            Assert.AreEqual(new Size(35, 119), stack.DesiredSize);
        }
        public void VerifyPaddingAndBorderThicknessLayoutOffset()
        {
            RunOnUIThread.Execute(() =>
            {
                double width              = 400;
                double height             = 400;
                Thickness borderThickness = new Thickness(5, 10, 15, 20);
                Thickness padding         = new Thickness(2, 4, 6, 8);

                LayoutPanel panel     = new LayoutPanel();
                panel.Width           = width;
                panel.Height          = height;
                panel.BorderBrush     = new SolidColorBrush(Colors.Red);
                panel.BorderThickness = borderThickness;
                panel.Padding         = padding;

                var button = new Button {
                    Content = "Button", VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch
                };
                var expectedButtonLayoutSlot = new Rect
                {
                    Width  = width - borderThickness.Left - borderThickness.Right - padding.Left - padding.Right,
                    Height = height - borderThickness.Top - borderThickness.Bottom - padding.Top - padding.Bottom,
                    X      = borderThickness.Left + padding.Left,
                    Y      = borderThickness.Top + padding.Top,
                };
                panel.Children.Add(button);

                Content = panel;
                Content.UpdateLayout();

                Verify.AreEqual(expectedButtonLayoutSlot, LayoutInformation.GetLayoutSlot(button), "Verify LayoutSlot of child Button");
            });
        }
Exemplo n.º 5
0
 private static Rect BoundsRelativeTo(this FrameworkElement element,
                                      Visual relativeTo)
 {
     return
         (element.TransformToVisual(relativeTo)
          .TransformBounds(LayoutInformation.GetLayoutSlot(element)));
 }
Exemplo n.º 6
0
            /// <summary>Обработчик вызываемый при изменении выделяемого для элемента места.</summary>
            /// <param name="sender"><see langword="null"/>.</param>
            /// <param name="e">Empty or <see langword="null"/>.</param>
            private void Element_LayoutUpdated(object sender = null, EventArgs e = null)
            {
                if (WidthToHeight <= 0)
                {
                    return;
                }

                /// Получение информации о выделенном месте
                Rect rect = LayoutInformation.GetLayoutSlot(Element);

                /// Размеры выделенной области с учётом Margin элемента
                double widthArea  = rect.Width - Element.Margin.Left - Element.Margin.Right;
                double heightArea = rect.Height - Element.Margin.Top - Element.Margin.Bottom;

                double width  = widthArea;
                double height = width * WidthToHeight;

                if (height > heightArea)
                {
                    height = heightArea;
                    width  = height / WidthToHeight;
                }
                Element.Width  = width > 0.0 ? width : 0.0;
                Element.Height = height > 0.0 ? height : 0.0;
            }
Exemplo n.º 7
0
        public void ClippingCanvasTest_notree()
        {
            var mine = new UserControlPoker()
            {
                Width = 30, Height = 30
            };
            var content = new Canvas()
            {
                Width = 50, Height = 50
            };

            mine.SetContent(content);

            mine.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

            Assert.AreEqual(new Size(30, 30), mine.MeasureArg, "MeasureArg");
            Assert.AreEqual(new Size(30, 30), mine.MeasureResult, "MeasureResult");
            Assert.AreEqual(new Size(30, 30), mine.DesiredSize, "poker Desired");
            Assert.AreEqual(new Size(30, 30), content.DesiredSize, "canvas desired");

            mine.Arrange(new Rect(0, 0, mine.DesiredSize.Width, mine.DesiredSize.Height));

            Assert.AreEqual(new Size(30, 30), mine.ArrangeArg, "ArrangeArg");
            Assert.AreEqual(new Size(30, 30), mine.ArrangeResult, "ArrangeResult");
            Assert.AreEqual(new Size(50, 50), new Size(content.ActualWidth, content.ActualHeight), "content actual");
            Assert.AreEqual(new Size(50, 50), content.RenderSize, "content rendersize");
            Assert.AreEqual(new Rect(0, 0, 30, 30), LayoutInformation.GetLayoutSlot(content), "content slot");
            Assert.IsNull(LayoutInformation.GetLayoutClip(content), "clip");
        }
Exemplo n.º 8
0
        public void AlignmentTest()
        {
            Border      b     = new Border();
            Border      b2    = new Border();
            LayoutPoker poker = new LayoutPoker();

            b.Child  = b2;
            b2.Child = poker;
            b.Width  = 50;

            b2.HorizontalAlignment = HorizontalAlignment.Right;
            b2.VerticalAlignment   = VerticalAlignment.Bottom;

            poker.MeasureResult = new Size(20, 20);
            b.Measure(new Size(100, 100));

            Assert.AreEqual(new Size(50, 100), poker.MeasureArg, "poker m arg");
            Assert.AreEqual(new Size(20, 20), poker.DesiredSize, "poker m result");
            Assert.AreEqual(new Size(0, 0), poker.BaseMeasureResult, "poker base result");

            Assert.AreEqual(new Size(50, 20), b.DesiredSize, "b desiredsize");
            Assert.AreEqual(new Size(20, 20), b2.DesiredSize, "b2 desiredsize");

            poker.ArrangeResult = new Size(20, 20);
            b.Arrange(new Rect(0, 0, b.DesiredSize.Width, b.DesiredSize.Height));

            Assert.AreEqual(new Size(20, 20), poker.ArrangeArg, "poker aa");

            Assert.AreEqual(new Rect(0, 0, 20, 20).ToString(), LayoutInformation.GetLayoutSlot(poker).ToString(), "poker slot");
            Assert.AreEqual(new Rect(0, 0, 50, 20).ToString(), LayoutInformation.GetLayoutSlot(b2).ToString(), "b2 slot");
            Assert.AreEqual(new Rect(0, 0, 50, 20).ToString(), LayoutInformation.GetLayoutSlot(b).ToString(), "b slot");
        }
Exemplo n.º 9
0
        void ForceScrollOffsetCore(Point offset, Point expectedOffset, Rect expectedSlot, bool scrollable)
        {
            var          child  = ContentControlWithChild(200, 200);
            ScrollViewer viewer = new ScrollViewer {
                HorizontalScrollBarVisibility = scrollable ? ScrollBarVisibility.Visible : ScrollBarVisibility.Disabled,
                VerticalScrollBarVisibility   = scrollable ? ScrollBarVisibility.Visible : ScrollBarVisibility.Disabled,
                Content = child,
            };

            CreateAsyncTest(viewer, () => {
                ScrollContentPresenter presenter = viewer.FindFirstChild <ScrollContentPresenter> ();
                presenter.Width  = 100;
                presenter.Height = 100;

                presenter.SetHorizontalOffset(offset.X);
                presenter.SetVerticalOffset(offset.Y);
            }, () => {
                ScrollContentPresenter presenter = viewer.FindFirstChild <ScrollContentPresenter> ();

                Assert.AreEqual(expectedOffset.X, presenter.HorizontalOffset, "#1");
                Assert.AreEqual(expectedOffset.Y, presenter.VerticalOffset, "#2");

                Assert.AreEqual(expectedSlot, LayoutInformation.GetLayoutSlot(child), "#3");
            });
        }
Exemplo n.º 10
0
        public void ComputeActualWidthBorderMeasure()
        {
            Border b = new Border();
            Canvas c = new Canvas();

            b.Child = c;

            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c desired1");
            Assert.AreEqual(new Size(0, 0), new Size(c.ActualWidth, c.ActualHeight), "c actual1");
            Assert.AreEqual(new Rect(0, 0, 0, 0), LayoutInformation.GetLayoutSlot(c), "c slot");

            c.MaxWidth  = 25;
            c.Width     = 50;
            c.MinHeight = 33;

            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c desired2");
            Assert.AreEqual(new Size(0, 0), new Size(c.ActualWidth, c.ActualHeight), "c actual2");
            Assert.AreEqual(new Rect(0, 0, 0, 0), LayoutInformation.GetLayoutSlot(c), "c slot");

            b.Measure(new Size(100, 100));

            Assert.AreEqual(new Size(25, 33), c.DesiredSize, "c desired3");
            Assert.AreEqual(new Size(0, 0), new Size(c.ActualWidth, c.ActualHeight), "c actual3");

            Assert.IsTrue(c.UseLayoutRounding, "use rounding");
        }
Exemplo n.º 11
0
 public static Rect BoundsRelativeTo(this FrameworkElement element,
                                     FrameworkElement item)
 {
     return
         (element.TransformToVisual(item)
          .TransformBounds(LayoutInformation.GetLayoutSlot(element)));
 }
Exemplo n.º 12
0
        public void ComputeActualWidth()
        {
            Canvas c = new Canvas();

            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c desired");
            Assert.AreEqual(new Size(0, 0), new Size(c.ActualWidth, c.ActualHeight), "c actual1");

            c.MaxWidth  = 25;
            c.Width     = 50;
            c.MinHeight = 33;

            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c desired");
            Assert.AreEqual(new Size(25, 33), new Size(c.ActualWidth, c.ActualHeight), "c actual1");
            Assert.AreEqual(new Rect(0, 0, 0, 0), LayoutInformation.GetLayoutSlot(c), "c slot");

            c.Measure(new Size(100, 100));

            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c desired");
            Assert.AreEqual(new Size(25, 33), new Size(c.ActualWidth, c.ActualHeight), "c actual2");
            Assert.AreEqual(new Size(0, 0), c.RenderSize, "c render");

            c.Arrange(new Rect(0, 0, c.DesiredSize.Width, c.DesiredSize.Height));

            Assert.AreEqual(new Size(0, 0), c.DesiredSize, "c desired");
            Assert.AreEqual(new Size(25, 33), new Size(c.ActualWidth, c.ActualHeight), "c actual3");
            Assert.AreEqual(new Size(0, 0), c.RenderSize, "c render");
        }
Exemplo n.º 13
0
        /// <summary>
        /// Event handler for adjusting the shared size column in the license details wrap panel.
        /// </summary>
        /// <remarks>
        /// This is a quick and dirty solution and I hope there is a better way. See the notes above
        /// about shared size scope.
        /// </remarks>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        private void LicensePropertiesWrapPanel_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            WrapPanel panel = sender as WrapPanel;

            if (panel != null)
            {
                if (panel.Orientation == Orientation.Vertical)
                {
                    int    column   = 0;
                    double location = 0;

                    foreach (Grid item in panel.Children)
                    {
                        Rect slot = LayoutInformation.GetLayoutSlot(item);
                        if (slot.X != location)
                        {
                            column++;
                            location = slot.X;
                        }

                        string groupName = string.Format(CultureInfo.InvariantCulture, "Column{0}", column);

                        if (item.ColumnDefinitions.Count == 2 && item.ColumnDefinitions[0].SharedSizeGroup != groupName)
                        {
                            item.ColumnDefinitions[0].SharedSizeGroup = groupName;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Similar to GetLayoutSlot. Attempts to compute the actual location of the
        /// FrameworkElement within the layout slot.
        /// </summary>
        /// <param name="Element"></param>
        /// <returns></returns>
        public static Rect GetLocWithinParent(this FrameworkElement Element)
        {
            Rect loc = LayoutInformation.GetLayoutSlot(Element);

            // get the parent of the element.
            FrameworkElement fwParent = null;

            if (Element.Parent is FrameworkElement)
            {
                fwParent = Element.Parent as FrameworkElement;
            }

            if ((fwParent != null) && (fwParent is StackPanel))
            {
                StackPanel stackParent = fwParent as StackPanel;
                if (stackParent.Orientation == Orientation.Vertical)
                {
                    double adjust      = stackParent.VerticalAdjustToChildLayoutSlot();
                    double adjustedTop = loc.Top + adjust;
                    loc = new Rect(new Point(loc.Left, adjustedTop), loc.Size);
                }
            }

            return(loc);
        }
Exemplo n.º 15
0
        public void When_Child_Has_Fixed_Size_Smaller_than_Parent()
        {
            var parentSize = new Windows.Foundation.Size(100, 100);
            var childSize  = new Windows.Foundation.Size(500, 500);

            var SUT = new Border()
            {
                Width  = parentSize.Width,
                Height = parentSize.Height
            };

            var child = new View()
            {
                Width  = childSize.Width,
                Height = childSize.Height
            };

            SUT.Child = child;

            SUT.Measure(new Windows.Foundation.Size(100, 100));
            var measuredSize = SUT.DesiredSize;

            SUT.Arrange(new Windows.Foundation.Rect(0, 0, 100, 100));

            Assert.AreEqual(parentSize, measuredSize, $"(parentSize:{parentSize}) != (measuredSize:{measuredSize})");
            var expectedArrange = new Windows.Foundation.Rect(0, 0, parentSize.Width, parentSize.Height);
            var layoutSlot      = LayoutInformation.GetLayoutSlot(child);

            Assert.AreEqual(expectedArrange, layoutSlot, $"(expectedArrange:{expectedArrange}) != (layoutSlot: {layoutSlot})");
        }
Exemplo n.º 16
0
 internal virtual Geometry GetSelectionOutline(DataPoint dataPoint)
 {
     if (dataPoint.View != null)
     {
         FrameworkElement frameworkElement = dataPoint.View.MainView ?? dataPoint.View.MarkerView;
         if (frameworkElement != null)
         {
             Rect rect;
             if (dataPoint.View.AnchorRectOrientation == RectOrientation.None)
             {
                 Rect  layoutSlot  = LayoutInformation.GetLayoutSlot(frameworkElement);
                 Point anchorPoint = dataPoint.View.AnchorPoint;
                 rect = new Rect(anchorPoint.X - layoutSlot.Width / 2.0, anchorPoint.Y - layoutSlot.Height / 2.0, layoutSlot.Width, layoutSlot.Height);
             }
             else
             {
                 rect = dataPoint.View.AnchorRect;
             }
             return((Geometry) new RectangleGeometry()
             {
                 Rect = RectExtensions.TranslateToParent(rect, frameworkElement, (FrameworkElement)this.ChartArea)
             });
         }
     }
     return((Geometry)null);
 }
Exemplo n.º 17
0
        protected override void ReleaseOrderedSequence(FrameworkElement source, List <ElementSite> elements)
        {
            var sourceSite  = (FrameworkElementSite)GetActualSite(source);
            var stackPanel  = GetParentStackPanel(source);
            var orientation = stackPanel.Orientation;

            if (stackPanel.IsItemsHost)
            {
            }
            else
            {
                stackPanel.Children.Remove(sourceSite.Element);
                stackPanel.Children.Insert(elements.IndexOf(sourceSite), sourceSite.Element);
            }

            stackPanel.UpdateLayout();

            var offset = 0.0;

            foreach (var elementSite in elements.Cast <FrameworkElementSite>())
            {
                var child = elementSite.Element;
                var ls    = LayoutInformation.GetLayoutSlot(child);
                var size  = orientation == Orientation.Horizontal ? ls.Width : ls.Height;

                elementSite.SetDefinitionOffset(offset);

                offset += size;
            }
        }
Exemplo n.º 18
0
        private void OnDragStarted()
        {
            if (!(this.VisualParent is SplitContainer splitContainer))
            {
                return;
            }

            var adornerLayer = AdornerLayer.GetAdornerLayer(splitContainer);

            if (adornerLayer == null)
            {
                return;
            }

            resizeData = new ResizeData
            {
                BeforeElementSize = Orientation == Orientation.Horizontal
                    ? LayoutInformation.GetLayoutSlot(BeforeElement).Height
                    : LayoutInformation.GetLayoutSlot(BeforeElement).Width,
                AfterElementSize = Orientation == Orientation.Horizontal
                    ? LayoutInformation.GetLayoutSlot(AfterElement).Height
                    : LayoutInformation.GetLayoutSlot(AfterElement).Width,

                MinOffset      = resizeData.BeforeElementSize - 22.0,
                MaxOffset      = resizeData.AfterElementSize - 22.0,
                PreviewAdorner = new SplitPreviewAdorner(this)
            };

            adornerLayer.Add(this.resizeData.PreviewAdorner);
        }
Exemplo n.º 19
0
        public void ValidateNonVirtualLayoutWithItemsRepeater()
        {
            RunOnUIThread.Execute(() =>
            {
                var repeater          = new ItemsRepeater();
                repeater.Layout       = new NonVirtualStackLayout();
                repeater.ItemsSource  = Enumerable.Range(0, 10);
                repeater.ItemTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                         <Button Content='{Binding}' Height='100' />
                    </DataTemplate>");

                Content = repeater;
                Content.UpdateLayout();

                double expectedYOffset = 0;
                for (int i = 0; i < repeater.ItemsSourceView.Count; i++)
                {
                    var child = repeater.TryGetElement(i) as Button;
                    Verify.IsNotNull(child);
                    var layoutBounds = LayoutInformation.GetLayoutSlot(child);
                    Verify.AreEqual(expectedYOffset, layoutBounds.Y);
                    Verify.AreEqual(i, child.Content);
                    expectedYOffset += 100;
                }
            });
        }
Exemplo n.º 20
0
        private static OverlapKind Overlap(ScrollViewer parent, FrameworkElement child, double padding)
        {
            // Get child transform relative to parent
            //var transform = child.TransformToVisual(parent); // Unreliable on Windows Phone 7; throws ArgumentException sometimes
            var layoutSlot = LayoutInformation.GetLayoutSlot(child);
            var transform  = new TranslateTransform { /*X = layoutSlot.Left - parent.HorizontalOffset,*/
                Y = layoutSlot.Top - parent.VerticalOffset
            };
            // Get child bounds relative to parent
            var bounds = new Rect(transform.Transform(new Point()), transform.Transform(new Point(/*child.ActualWidth*/ 0, child.ActualHeight)));

            // Return kind of overlap
            if (Overlap(0 - padding, parent.ActualHeight + padding, bounds.Top, bounds.Bottom))
            {
                return(OverlapKind.Overlap);
            }
            else if (bounds.Top < 0)
            {
                return(OverlapKind.ChildAbove);
            }
            else
            {
                return(OverlapKind.ChildBelow);
            }
        }
Exemplo n.º 21
0
        public void ClippingCanvasTest()
        {
            var mine = new UserControlPoker()
            {
                Width = 30, Height = 30
            };
            var content = new Canvas()
            {
                Width = 50, Height = 50
            };

            mine.SetContent(content);

            CreateAsyncTest(mine, () => {
                Assert.AreEqual(new Size(30, 30), mine.MeasureArg, "MeasureArg");
                Assert.AreEqual(new Size(30, 30), mine.MeasureResult, "MeasureResult");
                Assert.AreEqual(new Size(30, 30), mine.DesiredSize, "poker Desired");
                Assert.AreEqual(new Size(30, 30), content.DesiredSize, "canvas desired");

                Assert.AreEqual(new Size(30, 30), mine.ArrangeArg, "ArrangeArg");
                Assert.AreEqual(new Size(30, 30), mine.ArrangeResult, "ArrangeArg");
                Assert.AreEqual(new Size(50, 50), new Size(content.ActualWidth, content.ActualHeight), "content actual");
                Assert.AreEqual(new Size(30, 30), mine.RenderSize, "uc rendersize");
                Assert.AreEqual(new Size(50, 50), content.RenderSize, "content rendersize");
                Assert.AreEqual(new Rect(0, 0, 30, 30), LayoutInformation.GetLayoutSlot(content), "content slot");
                Assert.IsNull(LayoutInformation.GetLayoutClip(content), "clip");
            }
                            );
        }
Exemplo n.º 22
0
        private void SizeForNormalMode(bool animate)
        {
            ContentControl container = (ContentControl)ItemContainerGenerator.ContainerFromItem(SelectedItem);

            if (null != container)
            {
                // Set height/translation to show just the selected item
                if (0 < container.ActualHeight)
                {
                    SetContentHeight(container.ActualHeight + container.Margin.Top + container.Margin.Bottom);
                }
                if (null != _itemsPresenterTranslateTransformPart)
                {
                    if (!animate)
                    {
                        _itemsPresenterTranslateTransformPart.Y = 0;
                    }
                    _translateAnimation.To   = container.Margin.Top - LayoutInformation.GetLayoutSlot(container).Top;
                    _translateAnimation.From = animate ? null : _translateAnimation.To;
                }
            }
            else
            {
                // Resize to minimum height
                SetContentHeight(0);
            }

            // Clear highlight of previously selected container
            ListPickerItem oldContainer = (ListPickerItem)ItemContainerGenerator.ContainerFromIndex(SelectedIndex);

            if (null != oldContainer)
            {
                oldContainer.IsSelected = false;
            }
        }
Exemplo n.º 23
0
        void DumpLayoutTree(DependencyObject d, StringBuilder sb, int depth)
        {
            string s = string.Format("<{0} Actual='{2}/{3}' Desired='{4}/{5}' Rendered='{6}/{7}' MinHeight='{8}' MaxHeight='{9}' MinWidth='{10}' MaxWidth='{11}' Margin='{12}' LayoutSlot='{13}' LayoutClip='{14}'{15}>",
                                     d.GetType().Name,
                                     null,
                                     ((FrameworkElement)d).ActualWidth,
                                     ((FrameworkElement)d).ActualHeight,
                                     ((FrameworkElement)d).DesiredSize.Width,
                                     ((FrameworkElement)d).DesiredSize.Height,
                                     ((FrameworkElement)d).RenderSize.Width,
                                     ((FrameworkElement)d).RenderSize.Height,
                                     ((FrameworkElement)d).MinHeight,
                                     ((FrameworkElement)d).MaxHeight,
                                     ((FrameworkElement)d).MinWidth,
                                     ((FrameworkElement)d).MaxWidth,
                                     ((FrameworkElement)d).Margin,
                                     LayoutInformation.GetLayoutSlot(((FrameworkElement)d)),
                                     FormatLayoutClip((FrameworkElement)d),
                                     VisualTreeHelper.GetChildrenCount(d) == 0 ? "/" : "");

            sb.AppendLine(string.Format("{0}{1}", new string('	', depth), s));
            if (VisualTreeHelper.GetChildrenCount(d) > 0)
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
                {
                    DumpLayoutTree(VisualTreeHelper.GetChild(d, i), sb, depth + 1);
                }

                sb.AppendLine(string.Format("{0}</{1}>", new string('	', depth), d.GetType().Name));
            }
        }
Exemplo n.º 24
0
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);

            if (this.popup == null || this.SelectedIndex < 0)
            {
                return;
            }

            var height = .0;

            for (var i = 0; i < this.SelectedIndex; i++)
            {
                var container = this.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
                if (container == null)
                {
                    continue;
                }

                height += LayoutInformation.GetLayoutSlot(container).Height;
            }

            this.popup.VerticalOffset -= this.prevOffsetH;
            this.popup.VerticalOffset += -height;

            this.prevOffsetH = -height;
        }
Exemplo n.º 25
0
        public void LayoutSlotTest3()
        {
            Border b     = new Border();
            var    stack = new StackPanel();

            var panel = new Canvas();

            panel.Children.Add(b);

            panel.Background = new SolidColorBrush(Colors.Green);

            stack.Children.Add(CreateSlotItem());
            stack.Children.Add(CreateSlotItem());
            stack.Children.Add(CreateSlotItem());
            stack.HorizontalAlignment = HorizontalAlignment.Right;
            b.Width = 50;
            b.Child = stack;

            b.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            Assert.AreEqual(new Size(0, 0), new Size(stack.ActualWidth, stack.ActualHeight), "stack actual");

            b.Arrange(new Rect(0, 0, b.DesiredSize.Width, b.DesiredSize.Height));

            Assert.AreEqual(new Rect(0, 0, 25, 33).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[0]).ToString(), "slot0");
            Assert.AreEqual(new Rect(0, 33, 25, 33).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[1]).ToString(), "slot1");
            Assert.AreEqual(new Rect(0, 66, 25, 33).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[2]).ToString(), "slot2");
            Assert.AreEqual(new Rect(0, 0, 50, 99).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack).ToString());
            Assert.AreEqual(new Rect(0, 0, 50, 99).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)b).ToString());

            Assert.AreEqual(new Size(50, 99), b.DesiredSize);
            Assert.AreEqual(new Size(25, 99), stack.DesiredSize);
            Assert.AreEqual(new Size(25, 99), new Size(stack.ActualWidth, stack.ActualHeight), "stack actual");
            Assert.AreEqual(new Size(25, 99), stack.RenderSize, "stack render");
        }
Exemplo n.º 26
0
        public void LayoutCanvasInTreeTest()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text = tb.Text = "The truth is Hidden";
            sub.Child   = sub_tb;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            CreateAsyncTest(parent, () => {
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Width, sub_tb.ActualWidth, 1, "RenderWidth");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Height, sub_tb.ActualHeight, 1, "RenderHeight");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are notequal");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has no clip");
                Rect slot = LayoutInformation.GetLayoutSlot(sub_tb);
                Assert.IsTrue(Math.Ceiling(sub_tb.ActualWidth) == slot.Width, "slot is rounded up to actual");
            });
        }
Exemplo n.º 27
0
        public void AlignmentTest3()
        {
            Border b     = new Border();
            var    stack = new StackPanel();

            stack.Children.Add(new Border());
            stack.Children.Add(new Border());
            stack.Children.Add(new Border());
            stack.HorizontalAlignment = HorizontalAlignment.Right;
            b.Width     = 50;
            stack.Width = 50;
            b.Child     = stack;

            b.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            b.Arrange(new Rect(0, 0, b.DesiredSize.Width, b.DesiredSize.Height));

            Assert.AreEqual(new Rect(0, 0, 50, 0).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[0]).ToString(), "child 0");
            Assert.AreEqual(new Rect(0, 0, 50, 0).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[1]).ToString(), "child 1");
            Assert.AreEqual(new Rect(0, 0, 50, 0).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack.Children[2]).ToString(), "child 2");
            Assert.AreEqual(new Rect(0, 0, 50, 0).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)stack).ToString(), "stack slot");
            Assert.AreEqual(new Rect(0, 0, 50, 0).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)b).ToString(), "b slot");

            Assert.AreEqual(new Size(0, 0), stack.Children[0].DesiredSize, "child 0 desired");
            Assert.AreEqual(new Size(50, 0), b.DesiredSize, "b desired");
            Assert.AreEqual(new Size(50, 0), stack.DesiredSize, "stack desired");
        }
Exemplo n.º 28
0
        public void LayoutCanvasInTreeWrapTest()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text     = tb.Text = "The truth is Hidden";
            sub.Child       = sub_tb;
            tb.TextWrapping = sub_tb.TextWrapping = TextWrapping.Wrap;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            // Notice that we don't wrap even though the slot is slightly
            // smaller than our actual

            CreateAsyncTest(parent, () => {
                Assert.IsTrue(tb.UseLayoutRounding, "use layout rounding");
                Assert.IsTrue(sub_tb.UseLayoutRounding, "use layout rounding");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are notequal");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Width, sub_tb.ActualWidth, 1, "RenderWidth");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Height, sub_tb.ActualHeight, 1, "RenderHeight");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has no clip");
                Rect slot = LayoutInformation.GetLayoutSlot(sub_tb);
                Assert.IsTrue(Math.Ceiling(sub_tb.ActualWidth) == slot.Width, "slot is rounded up to actual");
            });
        }
Exemplo n.º 29
0
        void OnGridLoaded(object sender, RoutedEventArgs e)
        {
            Window           parent        = GetParentWindow(this);
            FrameworkElement windowContent = ((parent.Content) as FrameworkElement);
            Rect             r             = LayoutInformation.GetLayoutSlot(this);

            //HACK: Window border size heuristic - This assumes symmetric width of border and height of bottom border
            double windowLeftMargin = (parent.ActualWidth - windowContent.ActualWidth) / 2;
            //Determine top margin by subtracting border height of bottom border(which is same as left border)
            double windowTopMargin = (parent.ActualHeight - windowContent.ActualHeight) - windowLeftMargin;

            if (_GLWindow != null)
            {
                _GLWindow.Close();
            }

            _GLWindow = new DocumentView();

            _GLWindow.Left   = parent.Left + windowLeftMargin;
            _GLWindow.Top    = parent.Top + r.Top + windowTopMargin + 53;
            _GLWindow.Width  = r.Width;
            _GLWindow.Height = r.Height;;

            _GLWindow.Owner = parent;
            _GLWindow.Show();

            var wih = new WindowInteropHelper(_GLWindow);
            // GLCreate(wih.Handle.ToInt32());
        }
Exemplo n.º 30
0
        private void RadialController_ScreenContactStarted(RadialController sender,
                                                           RadialControllerScreenContactStartedEventArgs args)
        {
            Point contactPosition = args.Contact.Position;
            Rect  contactBounds   = args.Contact.Bounds;
            Rect  containerRect;

            for (int i = 0; i < menuItems.Count; ++i)
            {
                // Assuming Position is the center point of the wheel device on the digitizer surface.
                // If wheel device contact is within bounding rect of
                containerRect = containers[i].TransformToVisual(this).TransformBounds(
                    LayoutInformation.GetLayoutSlot(containers[i]));
                if ((contactPosition.X < (containerRect.X + containerRect.Width)) &&
                    (contactPosition.Y < (containerRect.Y + containerRect.Height)))
                {
                    if (radialController.Menu.Items.Contains(menuItems[i]))
                    {
                        OnItemInvoked(i);
                    }
                    break;
                }
            }
            AddToLog("\nScreen contact started (Location: " + contactPosition.X.ToString() + " " + contactPosition.Y.ToString() + " / Bounds: " + contactBounds.X.ToString() + " " + contactBounds.Y.ToString() + " " + contactBounds.Width.ToString() + " " + contactBounds.Height.ToString() + ")");
        }