Exemplo n.º 1
0
        public void Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent()
        {
            using (CreateServices())
            {
                PopupContentControl target;
                var root = PreparedWindow(target = new PopupContentControl
                {
                    Content  = new Border(),
                    Template = new FuncControlTemplate <PopupContentControl>(PopupContentControlTemplate),
                });
                root.Show();

                target.ApplyTemplate();

                var popup = (Popup)target.GetTemplateChildren().First(x => x.Name == "popup");
                popup.Open();

                var popupRoot = (Control)popup.Host;
                popupRoot.Measure(Size.Infinity);
                popupRoot.Arrange(new Rect(popupRoot.DesiredSize));

                var children = popupRoot.GetVisualDescendants().ToList();
                var types    = children.Select(x => x.GetType().Name).ToList();

                Assert.Equal(
                    new[]
                {
                    "Panel",
                    "Border",
                    "VisualLayerManager",
                    "ContentPresenter",
                    "ContentPresenter",
                    "Border",
                },
                    types);

                var templatedParents = children
                                       .OfType <IControl>()
                                       .Select(x => x.TemplatedParent).ToList();

                Assert.Equal(
                    new object[]
                {
                    popupRoot,
                    popupRoot,
                    popupRoot,
                    popupRoot,
                    target,
                    null,
                },
                    templatedParents);
            }
        }
Exemplo n.º 2
0
        public void Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent()
        {
            using (CreateServices())
            {
                PopupContentControl target;
                var root = new TestRoot
                {
                    Child = target = new PopupContentControl
                    {
                        Content  = new Border(),
                        Template = new FuncControlTemplate <PopupContentControl>(PopupContentControlTemplate),
                    },
                    StylingParent = AvaloniaLocator.Current.GetService <IGlobalStyles>()
                };

                target.ApplyTemplate();
                var popup = (Popup)target.GetTemplateChildren().First(x => x.Name == "popup");
                popup.Open();
                var popupRoot = popup.PopupRoot;

                var children = popupRoot.GetVisualDescendants().ToList();
                var types    = children.Select(x => x.GetType().Name).ToList();

                Assert.Equal(
                    new[]
                {
                    "ContentPresenter",
                    "ContentPresenter",
                    "Border",
                },
                    types);

                var templatedParents = children
                                       .OfType <IControl>()
                                       .Select(x => x.TemplatedParent).ToList();

                Assert.Equal(
                    new object[]
                {
                    popupRoot,
                    target,
                    null,
                },
                    templatedParents);
            }
        }
Exemplo n.º 3
0
        public void Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent()
        {
            using (CreateServices())
            {
                PopupContentControl target;
                var root = new TestRoot
                {
                    Child = target = new PopupContentControl
                    {
                        Content = new Border(),
                        Template = new FuncControlTemplate<PopupContentControl>(PopupContentControlTemplate),
                    }
                };

                target.ApplyTemplate();
                var popup = (Popup)target.GetTemplateChildren().First(x => x.Name == "popup");
                popup.Open();
                var popupRoot = popup.PopupRoot;

                var children = popupRoot.GetVisualDescendents().ToList();
                var types = children.Select(x => x.GetType().Name).ToList();

                Assert.Equal(
                    new[]
                    {
                        "ContentPresenter",
                        "ContentPresenter",
                        "Border",
                    },
                    types);

                var templatedParents = children
                    .OfType<IControl>()
                    .Select(x => x.TemplatedParent).ToList();

                Assert.Equal(
                    new object[]
                    {
                        popupRoot,
                        target,
                        null,
                    },
                    templatedParents);
            }
        }