DisplayingHTMLinSilverlightApplications
DanWahlin
RichInternetApplication(RIA)technologiesprovidedeveloperswithaflexibledevelopment
environmentthatcandisplaydataandmediainavarietyofways.Newfeaturesavailablein
Silverlight4suchasfluidUIsupportinlistboxesandanimationtransitionsallowdatatobe
displayedincreativewaystouserswithoutrelyingoncustomJavaScriptorCSS.
Evenwithallofthesepowerfulfeatures,manyapplicationsstillhavetheneedtodisplayHTML
content.ForexampleyoumayneedtodisplayRSSdata(it’squitecommonforHTMLtobe
embeddedinRSSfeeds)ormayneedtoshowawebpageoraSQLServerReportingServices
(SSRS)reportdirectlyinyourSilverlightapplication.YoumayevenwanttodisplayaPDF
document.Howdoyoudothesetypesofthingswithoutcompletelydisruptingtheflowand
consistencyoftheapplication’suserinterface?
InthisarticleI'lldiscussoptionsfordisplayingHTMLcontentinSilverlightapplicationsand
describehowmycompanyisusingthesetechniquesinanexistingclientapplicationthat'sbeing
built.Let'sgetstartedbytalkingaboutdifferenttechniquesthatcanbeusedtodisplayHTMLin
Silverlightapplications.
HTMLDisplayOptions
SeveraldifferenttechniquescanbeusedtodisplayHTMLcontentinanapplicationincluding
HTMLoverlays,minimizingSilverlightsothatHTMLobjectscanbeshownorusingthenew
WebBrowsercontrolinSilverlight4out‐of‐browser applications.I'llfocusonthelattertwo
optionsinthisarticleanddescribehowwehandledshowingHTMLreportsgeneratedbySSRS
aswellasPDFprintinginaSilverlightapplication.
OneofthemorecommontechniquesfordisplayingcontentinSilverlightapplicationsrunning
inthebrowseristouseHTMLoverlays.GoingthisrouteallowsHTMLcontenttobeplacedona
SilverlightapplicationbytakingadvantageofbasicHTMLandCSSfeatures.Forexample,adiv
containercanbepositionedaboveanapplicationtodisplayachunkofHTMLcontent.
ThesecondtechniquethatcanbeusedfordisplayingHTMLcontentistouseCSSandJavaScript
toyouradvantageandminimizetheheightorwidthofaSilverlightapplicationwillmaximizing
theheightofahiddendivcontainer.We'reusingthistechniquealottodisplaySSRSreports
whileSilverlightisrunninginthebrowser.
Thefinaltechniquethatcanbeusedistheeasiesttoputintoplaybutisonly
availableinout‐
of‐browserapplications.Silverlight4providesaWebBrowsercontrolthatallowscontenttobe
displayeddirectlybyassigningaURItothecontrol'sSourcepropertyorbypassingHTMLtothe
NavigateTo()method.I'llprovidemoredetailsonusingtheWebBrowsercontroltowardthe
endofthearticleanddescribehowitcanbeusedinyourapplications.