1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
   | public class HtmlDisplay : ContentControl
    {
        private HtmlElement div;
        private HtmlElement iFrame;
        public HtmlDocument htmlDocument = HtmlPage.Document;
 
        public HtmlDisplay()
        {
            this.Loaded += new RoutedEventHandler(HtmlDisplay_Loaded);
        }
 
        void HtmlDisplay_Loaded(object sender, RoutedEventArgs e)
        {
 
 
            div = htmlDocument.CreateElement("div");
            div.Id = "monDiv";
            div.SetStyleAttribute("position", "absolute");
            div.SetStyleAttribute("height", this.Height.ToString() + "px");
            div.SetStyleAttribute("width", this.Width.ToString() + "px");
            GeneralTransform gt = this.TransformToVisual(Application.Current.RootVisual);
            Point position = gt.Transform(new Point(0, 0));
            div.SetStyleAttribute("left", position.X + "px");
            div.SetStyleAttribute("top", position.Y + "px");
            iFrame = htmlDocument.CreateElement("iframe");
            iFrame.Id = "monIFrame";
            iFrame.SetProperty("frameborder", "no");
            iFrame.SetStyleAttribute("height", this.Height.ToString() + "px");
            iFrame.SetStyleAttribute("width", this.Width.ToString() + "px");
            iFrame.SetStyleAttribute("position", "relative");
            div.AppendChild(iFrame);
            htmlDocument.Body.AppendChild(div);
            //htmlDocument.GetElementById("monIFrame").Invoke("test");
 
        }
} | 
Partager