protected override void OnTemplateModeChanged() { base.OnTemplateModeChanged(); if (InTemplateMode) { // Set xmlns in view linked document to show HTML intrinsic // controls in property grid with same schema used by // Intellisense for current choice tag in HTML view. NativeMethods.IHTMLElement htmlElement = (NativeMethods.IHTMLElement)((IControlDesignerBehavior)Behavior).DesignTimeElementView; Debug.Assert(htmlElement != null, "Invalid HTML element in MobileTemplateControlDesigner.OnTemplateModeChanged"); NativeMethods.IHTMLDocument2 htmlDocument2 = (NativeMethods.IHTMLDocument2)htmlElement.GetDocument(); Debug.Assert(htmlDocument2 != null, "Invalid HTML Document2 in MobileTemplateControlDesigner.OnTemplateModeChanged"); NativeMethods.IHTMLElement htmlBody = (NativeMethods.IHTMLElement)htmlDocument2.GetBody(); Debug.Assert(htmlBody != null, "Invalid HTML Body in MobileTemplateControlDesigner.OnTemplateModeChanged"); htmlBody.SetAttribute("xmlns", (Object)CurrentChoice.Xmlns, 0); } }
/// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.Initialize"]/*' /> /// <devdoc> /// Initialize from content by creating the necessary HTML element tree structure, etc. /// </devdoc> private void Initialize() { if (this.htmlElemFrame != null) { return; } try { NativeMethods.IHTMLDocument2 htmlDocument = (NativeMethods.IHTMLDocument2)htmlElemParent.GetDocument(); // Create an HTML element that would represent the entire template frame. this.htmlElemFrame = htmlDocument.CreateElement("SPAN"); // Place the provided content within the frame htmlElemFrame.SetInnerHTML(this.Content); // Hold on to the top-level HTML element of the template frame content. NativeMethods.IHTMLDOMNode domNodeFrame = (NativeMethods.IHTMLDOMNode)htmlElemFrame; if (domNodeFrame != null) { this.htmlElemContent = (NativeMethods.IHTMLElement)domNodeFrame.GetFirstChild(); } // Mark the frame as not editable! NativeMethods.IHTMLElement3 htmlElement3 = (NativeMethods.IHTMLElement3)htmlElemFrame; if (htmlElement3 != null) { htmlElement3.SetContentEditable("false"); } // Create an array to hold the HTML elements representing the individual templates. templateElements = new object[templateNames.Length]; Object varName; Object varIndex = (int)0; NativeMethods.IHTMLElementCollection allCollection = (NativeMethods.IHTMLElementCollection)htmlElemFrame.GetAll(); // Obtain all the children of the frame and hold on to the ones representing the templates. for (int i = 0; i < templateNames.Length; i++) { try { varName = templateNames[i]; NativeMethods.IHTMLElement htmlElemTemplate = (NativeMethods.IHTMLElement)allCollection.Item(varName, varIndex); // Set an expando attribute (on the above HTML element) called "TemplateName" // which contains the name of the template it corresponds to. htmlElemTemplate.SetAttribute("templatename", varName, /*lFlags*/ 0); // Place an editable DIV within the individual templates. // This is needed in order for, say, TABLEs, TRs, TDs, etc., to be editable in a // view-linked markup. string editableDIV = "<DIV contentEditable=\"true\" style=\"padding:1;height:100%;width:100%\"></DIV>"; htmlElemTemplate.SetInnerHTML(editableDIV); // The first child of the template element will be the above editable SPAN. NativeMethods.IHTMLDOMNode domNodeTemplate = (NativeMethods.IHTMLDOMNode)htmlElemTemplate; if (domNodeTemplate != null) { templateElements[i] = domNodeTemplate.GetFirstChild(); } } catch (Exception ex) { Debug.Fail(ex.ToString()); templateElements[i] = null; } } // Hold on to the HTML element within which the control name should get displayed. // The presence of this element is optional. varName = "idControlName"; this.htmlElemControlName = (NativeMethods.IHTMLElement)allCollection.Item(varName, varIndex); // Retrieve the HTML element within which the template frame name should be displayed. // The presence of this element is optional. // We also don't hold on to it, since the name of the template frame can't be changed. varName = "idFrameName"; object objFrameName = allCollection.Item(varName, varIndex); if (objFrameName != null) { NativeMethods.IHTMLElement htmlElemFrameName = (NativeMethods.IHTMLElement)objFrameName; htmlElemFrameName.SetInnerText(frameName); } NativeMethods.IHTMLDOMNode domNodeParent = (NativeMethods.IHTMLDOMNode)htmlElemParent; if (domNodeParent == null) { return; } domNodeParent.AppendChild(domNodeFrame); } catch (Exception ex) { Debug.Fail(ex.ToString()); } }