Пример #1
0
        public void When_ManuallyApplyTemplate_OutOfVisualTree()
        {
            var current = FeatureConfiguration.Control.UseLegacyLazyApplyTemplate;

            try
            {
                FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = true;
                var templatedRoot = default(UIElement);
                var sut           = new MyControl
                {
                    Template = new ControlTemplate(() => templatedRoot = new Grid())
                };

                Assert.IsNull(sut.TemplatedRoot);
                Assert.IsNull(templatedRoot);

                var applied = sut.ApplyTemplate();

                Assert.IsTrue(applied);
                Assert.IsNotNull(sut.TemplatedRoot);
                Assert.AreSame(templatedRoot, sut.TemplatedRoot);
            }
            finally
            {
                FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = current;
            }
        }
Пример #2
0
        public void CustomDataTemplate()
        {
            MyControl c = (MyControl)XamlReader.Load(@"
<x:MyControl xmlns=""http://schemas.microsoft.com/client/2007""
			xmlns:x=""clr-namespace:MoonTest.System.Windows;assembly=moon-unit"">
	<x:MyControl.ContentTemplate>
		<x:MyDataTemplate>
			<Rectangle />
		</x:MyDataTemplate>
	</x:MyControl.ContentTemplate>
</x:MyControl>");
            Rectangle r = new Rectangle();

            c.Content = r;
            c.ApplyTemplate();

            // Check that the visual tree matches up:
            // MyControl->ContentPresenter->Rectangle
            CreateAsyncTest(c,
                            () =>
            {
                Assert.VisualChildren(c,
                                      new VisualNode <ContentPresenter>("#1",
                                                                        new VisualNode <Rectangle>("#2")
                                                                        )
                                      );
            }
                            );
        }
Пример #3
0
        public void When_ManuallyApplyTemplate()
        {
            var current = FeatureConfiguration.Control.UseLegacyLazyApplyTemplate;

            try
            {
                FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = true;
                var templatedRoot = default(UIElement);
                var sut           = new MyControl
                {
                    Template = new ControlTemplate(() => templatedRoot = new Grid())
                };

                Assert.IsNull(sut.TemplatedRoot);
                Assert.IsNull(templatedRoot);

                new Grid().Children.Add(sut);                 // This kind-of simulate that the control is in the visual tree.

                Assert.IsNull(sut.TemplatedRoot);
                Assert.IsNull(templatedRoot);

                var applied = sut.ApplyTemplate();

                Assert.IsTrue(applied);
                Assert.IsNotNull(sut.TemplatedRoot);
                Assert.AreSame(templatedRoot, sut.TemplatedRoot);
            }
            finally
            {
                FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = current;
            }
        }
Пример #4
0
        public void When_ManualyApplyTemplate_OutOfVisualTree()
        {
            var templatedRoot = default(UIElement);
            var sut           = new MyControl
            {
                Template = new ControlTemplate(() => templatedRoot = new Grid())
            };

            Assert.IsNull(sut.TemplatedRoot);
            Assert.IsNull(templatedRoot);

            var applied = sut.ApplyTemplate();

            Assert.IsFalse(applied);
            Assert.IsNull(sut.TemplatedRoot);
            Assert.IsNull(templatedRoot);
        }
Пример #5
0
        public void When_ManualyApplyTemplate()
        {
            var templatedRoot = default(UIElement);
            var sut           = new MyControl
            {
                Template = new ControlTemplate(() => templatedRoot = new Grid())
            };

            Assert.IsNull(sut.TemplatedRoot);
            Assert.IsNull(templatedRoot);

            new Grid().Children.Add(sut);             // This kind-of simulate that the control is in the visual tree.

            Assert.IsNull(sut.TemplatedRoot);
            Assert.IsNull(templatedRoot);

            var applied = sut.ApplyTemplate();

            Assert.IsTrue(applied);
            Assert.IsNotNull(sut.TemplatedRoot);
            Assert.AreSame(templatedRoot, sut.TemplatedRoot);
        }