This custom ContentControl changes its ContentTemplate based on the content it is presenting.
In order to determine the template it must use for the new content, this control retrieves it from its resources using the name for the type of the new content as the key.
Inheritance: System.Windows.Controls.ContentControl
Exemplo n.º 1
0
        public void WhenContentWithoutMatchingResourceSet_SetsTemplateToNull()
        {
            var selector = new DataTemplateSelector();
            var originalDataTemplate = new DataTemplate();
            selector.ContentTemplate = originalDataTemplate;

            selector.Content = new FirstContentType();

            Assert.IsNull(selector.ContentTemplate);
        }
Exemplo n.º 2
0
        public void WhenContentSet_SelectsTemplateFromResourceByName()
        {
            var selector = new DataTemplateSelector();
            var dataTemplate = new DataTemplate();
            Assert.AreNotSame(dataTemplate, selector.ContentTemplate);

            selector.Resources.Add("FirstContentType", dataTemplate);

            selector.Content = new FirstContentType();
            Assert.AreSame(dataTemplate, selector.ContentTemplate);
        }
Exemplo n.º 3
0
        public void WhenContentIsNull_ThenSetsTemplateToNull()
        {
            var selector = new DataTemplateSelector();
            var originalDataTemplate = new DataTemplate();

            selector.Content = new object();
            selector.ContentTemplate = originalDataTemplate;

            selector.Content = null;

            Assert.IsNull(selector.ContentTemplate);
        }
Exemplo n.º 4
0
        public void WhenChangingContentType_TemplateIsUpdatedBasedOnType()
        {
            var selector = new DataTemplateSelector();
            var firstDataTemplate = new DataTemplate();
            var secondDataTemplate = new DataTemplate();
            
            selector.Resources.Add("FirstContentType", firstDataTemplate);
            selector.Resources.Add("SecondContentType", secondDataTemplate);

            selector.Content = new FirstContentType();
            Assert.AreSame(firstDataTemplate, selector.ContentTemplate);

            selector.Content = new SecondContentType();
            Assert.AreSame(secondDataTemplate, selector.ContentTemplate);
        }