Skip to Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

WPF and HTML

Unlike ActiveX or Windows Forms controls, WPF elements cannot be hosted directly on an HTML page (i.e., there's nothing to support this kind of thing in HTML), as shown in Example B-11.

Example B-11. WPF controls can't be hosted directly in HTML

<html>
  <body>
    <h1>WPF doesn't support anything like this!</h1>
    <object
      id="wpfctrl"
      classid="wpfctrl.dll#wpfctrl.MyWpfControl"
      width="100"
      height="100">
    </object>
  </body>
</html>

You can get around this issue again by hosting a WPF control on a custom Windows Forms User Control. Or, if you've got a WPF XBAP as described in Chapter 11, you can host it as a frame as shown in Example B-12.

Example B-12. WPF XBAP hosted in an HTML iframe

<html>
  <body>
    <h1>WPF supports this!</h1>
    <iframe src="MyWpfApp.xbap"></iframe>
  </body>
</html>

The downside of this approach is that the WPF application cannot provide any programmatic interface (e.g., properties, methods, or events) to the surrounding HTML, like an ActiveX control would.

To go the other way and host HTML inside WPF is a matter of bringing either the COM or the Windows Forms Web Browser control into your WPF app and feeding it HTML. Or, if the HTML is available via a URL, you can navigate to it on a navigation host, as Example B-13 illustrates.

Example B-13. Navigating to an URL using a WPF navigation host

<Page ...>
  <Grid>
    <TextBlock>
      Check out
        <Hyperlink
          NavigateUri="http://sellsbrothers.com">sellsbrothers.com</Hyperlink>.
    </TextBlock>
  </Grid>
</Page>

Because the link references ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Practical WPF Charts and Graphics

Practical WPF Charts and Graphics

Jack Xu
Illustrated WPF

Illustrated WPF

Daniel Solis
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Errata Page