private static CodeExpression GetControlTemplateValueExpression(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName)
        {
            ControlTemplate  controlTemplate = value as ControlTemplate;
            DependencyObject content         = controlTemplate.LoadContent();
            string           variableName    = baseName + "_ct";
            string           creator         = CodeComHelper.GenerateTemplate(parentClass, method, content, variableName);
            Type             targetType      = controlTemplate.TargetType;
            CodeVariableDeclarationStatement controlTemplateVar;

            if (targetType != null)
            {
                controlTemplateVar = new CodeVariableDeclarationStatement(
                    "ControlTemplate", variableName,
                    new CodeObjectCreateExpression("ControlTemplate", new CodeTypeOfExpression(targetType.Name), new CodeSnippetExpression(creator)));
            }
            else
            {
                controlTemplateVar = new CodeVariableDeclarationStatement(
                    "ControlTemplate", variableName,
                    new CodeObjectCreateExpression("ControlTemplate", new CodeSnippetExpression(creator)));
            }

            method.Statements.Add(controlTemplateVar);

            TriggerCollection triggers = controlTemplate.Triggers;

            CodeComHelper.GenerateTriggers(parentClass, method, variableName, targetType, triggers);

            return(new CodeVariableReferenceExpression(variableName));
        }
        private static CodeExpression GetItemsPanelTemplateValueExpression(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName)
        {
            ItemsPanelTemplate template     = value as ItemsPanelTemplate;
            DependencyObject   content      = template.LoadContent();
            string             variableName = baseName + "_ipt";
            string             creator      = CodeComHelper.GenerateTemplate(parentClass, method, content, variableName);
            CodeVariableDeclarationStatement templateVar = new CodeVariableDeclarationStatement(
                "ControlTemplate", variableName,
                new CodeObjectCreateExpression("ControlTemplate", new CodeSnippetExpression(creator)));

            method.Statements.Add(templateVar);
            return(new CodeVariableReferenceExpression(variableName));
        }
Example #3
0
        private static CodeExpression GetDataTemplateValueExpression(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName)
        {
            DataTemplate     dataTemplate = value as DataTemplate;
            Type             dataType     = dataTemplate.DataType as Type;
            DependencyObject content      = dataTemplate.LoadContent();
            string           variableName = baseName + "_dt";
            string           creator      = CodeComHelper.GenerateTemplate(parentClass, method, content, variableName);

            if (dataType != null)
            {
                return(new CodeObjectCreateExpression("DataTemplate", new CodeTypeOfExpression(dataType.FullName), new CodeSnippetExpression(creator)));
            }

            return(new CodeObjectCreateExpression("DataTemplate", new CodeSnippetExpression(creator)));
        }