Exemple #1
0
        public void Replacing_Template_Releases_Events()
        {
            var p1 = new ContentPresenter {
                Name = "Content_1_Presenter"
            };
            var p2 = new ContentPresenter {
                Name = "Content_2_Presenter"
            };
            var target = new TestControl
            {
                Template = new FuncControlTemplate((_, scope) => new Panel
                {
                    Children =
                    {
                        p1.RegisterInNameScope(scope),
                        p2.RegisterInNameScope(scope)
                    }
                })
            };

            target.ApplyTemplate();

            Control tc;

            p1.Content = tc = new Control();
            p1.UpdateChild();
            Assert.Contains(tc, target.GetLogicalChildren());

            p2.Content = tc = new Control();
            p2.UpdateChild();
            Assert.Contains(tc, target.GetLogicalChildren());

            target.Template = null;

            p1.Content = tc = new Control();
            p1.UpdateChild();
            Assert.DoesNotContain(tc, target.GetLogicalChildren());

            p2.Content = tc = new Control();
            p2.UpdateChild();
            Assert.DoesNotContain(tc, target.GetLogicalChildren());
        }