private void InsertElement() { // Create the DIV element. var doc = HtmlPage.Document; htmlElement = HtmlPage.Document.CreateElement("DIV"); // Apply attributes. htmlElement.SetAttribute("id", HtmlElementId); htmlElement.SetStyleAttribute("position", "absolute"); UpdateInnerHtml(); UpdateStyle(); // Wire up events. LayoutUpdated += OnLayoutUpdated; // Insert into page. doc.Body.AppendChild(htmlElement); }
void PositionElement() { if (currentDisplay == DisplayElement.Frame) { theDisplay = HtmlPage.Document.GetElementById("theFrame"); if (theDisplay == null) { theDisplay = HtmlPage.Document.CreateElement("IFrame"); theDisplay.SetAttribute("ID", "theFrame"); HtmlPage.Document.Body.AppendChild(theDisplay); } } else { theDisplay = HtmlPage.Document.GetElementById("theDiv"); if (theDisplay == null) { theDisplay = HtmlPage.Document.CreateElement("Div"); theDisplay.SetAttribute("ID", "theDiv"); theDisplay.SetStyleAttribute("backgroundColor", "white"); theDisplay.SetStyleAttribute("borderWidth", "1px"); theDisplay.SetStyleAttribute("borderColor", "black"); theDisplay.SetStyleAttribute("borderStyle", "solid"); HtmlPage.Document.Body.AppendChild(theDisplay); } } theDisplay.SetStyleAttribute("position", "absolute"); Point topleft = Position.GetAbsolutePosition(this.FrameContainer); int controlTop = (int)topleft.Y; int controlLeft = (int)topleft.X; theDisplay.SetStyleAttribute("left", controlLeft.ToString() + "px"); theDisplay.SetStyleAttribute("top", controlTop.ToString() + "px"); theDisplay.SetStyleAttribute("visibility", "visible"); theDisplay.SetStyleAttribute("width", this.FrameContainer.ActualWidth.ToString() + "px"); theDisplay.SetStyleAttribute("height", this.FrameContainer.ActualHeight.ToString() + "px"); }
/// <summary> /// Recreates the scratch html element. /// </summary> public void ClearScratchElement() { if (_scratchElement != null) { RemoveScratchElement(); } if (HtmlPage.IsEnabled && HtmlPage.Document != null) { _scratchElement = HtmlPage.Document.CreateElement("div"); _scratchElement.SetAttribute("id", DefaultScratchElementID); if (HtmlPage.Document.Body.Children.Count > 0) { HtmlElement first = HtmlPage.Document.Body.Children[0] as HtmlElement; HtmlPage.Document.Body.AppendChild(_scratchElement, first); } else { HtmlPage.Document.Body.AppendChild(_scratchElement); } _dirty = false; } }
private void InitializeHtml() { // Create Container Div Element _htmlDivContainerElement = System.Windows.Browser.HtmlPage.Document.CreateElement("div"); _htmlDivContainerElement.Id = this.HtmlDivContainerID; _htmlDivContainerElement.SetStyleAttribute("position", "absolute"); // Create A Element _htmlAnchorFocusElement = System.Windows.Browser.HtmlPage.Document.CreateElement("a"); _htmlAnchorFocusElement.SetAttribute("href", "#"); _htmlAnchorFocusElement.SetStyleAttribute("position", "absolute"); _htmlAnchorFocusElement.SetStyleAttribute("left", "0px"); _htmlAnchorFocusElement.SetStyleAttribute("top", "0px"); _htmlAnchorFocusElement.SetStyleAttribute("width", "0px"); _htmlAnchorFocusElement.SetStyleAttribute("height", "0px"); _htmlAnchorFocusElement.Id = this.HtmlAnchorFocusID; _htmlDivContainerElement.AppendChild(_htmlAnchorFocusElement); // Create Iframe Element _htmlIframeEditorElement = System.Windows.Browser.HtmlPage.Document.CreateElement("iframe"); _htmlIframeEditorElement.Id = this.HtmlIframeID; _htmlIframeEditorElement.SetAttribute("frameBorder", "0"); _htmlIframeEditorElement.SetAttribute("allowTransparency", "true"); _htmlIframeEditorElement.SetStyleAttribute("position", "relative"); _htmlIframeEditorElement.SetStyleAttribute("width", "100%"); _htmlIframeEditorElement.SetStyleAttribute("height", "100%"); _htmlDivContainerElement.AppendChild(_htmlIframeEditorElement); //System.Windows.Browser.HtmlPage.Document.Body.AppendChild(_htmlDivContainerElement); HtmlContainer.AppendChild(_htmlDivContainerElement); string initialText = !this.IsBrowserIE ? "<br/>" : ""; if (!string.IsNullOrEmpty(this.Text)) initialText = this.Text; StringBuilder sb = new StringBuilder(); sb.Append("setTimeout(function(){"); sb.Append(GetIframeDocumentScript()); if (this.IsBrowserIE) sb.AppendFormat("{0}.designMode = '{1}';", ScriptVariableIframeDocument, isReadOnly ? "Off" : "On"); sb.AppendFormat("{0}.open('text/html', 'replace');", ScriptVariableIframeDocument); sb.AppendFormat("{0}.write(\"{1}\");", ScriptVariableIframeDocument, this.GetInitialIframeOuterHTML()); sb.AppendFormat("{0}.close();", ScriptVariableIframeDocument); //sb.Append("setTimeout(function(){"); if (!this.IsBrowserIE) sb.AppendFormat("{0}.designMode = '{1}';", ScriptVariableIframeDocument, isReadOnly ? "Off" : "On"); StringBuilder sbInit = new StringBuilder(initialText); sbInit.Replace("\"", "\\\""); sbInit.Replace("\r", ""); sbInit.Replace("\n", ""); sb.AppendFormat("{0}.body.innerHTML = \"{1}\";", ScriptVariableIframeDocument, sbInit.ToString()); //sb.Append("}, 100);"); //sb.AppendFormat("document.getElementById('{0}').contentWindow.IsReady = true;", this.HtmlIframeID); sb.Append("var w;"); sb.AppendFormat("if({0}.parentWindow)", ScriptVariableIframeDocument); sb.AppendFormat(" w = {0}.parentWindow;", ScriptVariableIframeDocument); sb.AppendFormat("else if({0}.defaultView)", ScriptVariableIframeDocument); sb.AppendFormat(" w = {0}.defaultView;", ScriptVariableIframeDocument); sb.AppendFormat("else ", ScriptVariableIframeDocument); sb.AppendFormat(" w = {0}.parentWindow;", ScriptVariableIframeDocument); sb.Append("w.IsReady = true;"); sb.Append("}, 100);"); System.Windows.Browser.HtmlPage.Window.Eval(sb.ToString()); timerInitialize = new DispatcherTimer(); timerInitialize.Interval = TimeSpan.FromMilliseconds(100); timerInitialize.Tick += delegate { if (!_iframeInitialized) { timerInitialize.Stop(); if (_htmlIframeEditorElement == null) { Dispose(); return; } IntializeHandlersHtml(); if (!_iframeInitialized) timerInitialize.Start(); } }; timerInitialize.Start(); // _htmlInitialized = true; //ScratchHtml(); if (HtmlAnimationIframePlace != null) { HtmlAnimationPair hap = new HtmlAnimationPair(); hap.HtmlElementName = this.HtmlDivContainerID; //hap.HtmlContainerName = this.HtmlContainerID; hap.SLElement = ElementIframePlace; HtmlAnimationIframePlace.Pairs.Add(hap); HtmlAnimationIframePlace.ControlOwner = this; } Application.Current.RootVisual.MouseMove += new MouseEventHandler(RootVisual_MouseMove); }