Beginning Silverlight 4 in C#, 3rd Edition
® THE EXPERT’S VOICE
IN SILVERLIGHT
Beginning Silverlight 4 in
C# Learn to build state-of-the-art Silverlight applications quickly and easily
SOURCE CODE ONLINE
Robert Lair
Beginning Silverlight 4
in C#
■ ■ ■ RobertLair BeginningSilverlight4inC# Copyright©2010byRobertLair Allrightsreserved.Nopartofthisworkmaybereproducedortransmittedinanyformorbyanymeans, electronicormechanical,includingphotocopying,recording,orbyanyinformationstorageorretrieval system,withoutthepriorwrittenpermissionofthecopyrightownerandthepublisher.
ISBN-13(pbk):978-1-4302-2988-9
ISBN-13(electronic):978-1-4302-2989-6 PrintedandboundintheUnitedStatesofAmerica987654321 Trademarkednames,logos,andimagesmayappearinthisbook.Ratherthanuseatrademarksymbol witheveryoccurrenceofatrademarkedname,logo,orimageweusethenames,logos,andimagesonly inaneditorialfashionandtothebenefitofthetrademarkowner,withnointentionofinfringementof thetrademark. Theuseinthispublicationoftradenames,trademarks,servicemarks,andsimilarterms,eveniftheyare notidentifiedassuch,isnottobetakenasanexpressionofopinionastowhetherornottheyaresubject toproprietaryrights.
PresidentandPublisher:PaulManning LeadEditor:EwanBuckingham TechnicalReviewer:FabioClaudioFerracchiati EditorialBoard:ClayAndres,SteveAnglin,MarkBeckner,EwanBuckingham,GaryCornell,
JonathanGennick,JonathanHassell,MichelleLowman,MatthewMoodie,DuncanParkes, JeffreyPepper,FrankPohlmann,DouglasPundick,BenRenow-Clarke,DominicShakeshaft, MattWade,TomWelsh
CoordinatingEditor:DebraKelly CopyEditor:KatieStence ProductionSupport:PatrickCunningham Indexer:BIMIndexing&ProofreadingServices Artist:AprilMilne CoverDesigner:AnnaIshchenko
DistributedtothebooktradeworldwidebySpringerScience+BusinessMedia,LLC.,233SpringStreet, 6thFloor,NewYork,NY10013.Phone1-800-SPRINGER,fax(201)348-4505,e-mail Forinformationontranslations,pleasee-mail ApressandfriendsofEDbooksmaybepurchasedinbulkforacademic,corporate,orpromotionaluse. eBookversionsandlicensesarealsoavailableformosttitles.Formoreinformation,referenceour SpecialBulkSales–eBookLicensingwebpageat Theinformationinthisbookisdistributedonan“asis”basis,withoutwarranty.Althoughevery precautionhasbeentakeninthepreparationofthiswork,neithertheauthor(s)norApressshallhave anyliabilitytoanypersonorentitywithrespecttoanylossordamagecausedorallegedtobecaused directlyorindirectlybytheinformationcontainedinthiswork. Thesourcecodeforthisbookisavailabletoreadersat
In the memory of my Grandpa, James Wiles.
Contents at a Glance
AbouttheAuthor................................................................................... Acknowledgments....................................................................................
Chapter1:WelcometoSilverlight4................................................................ ■
Chapter2:IntroductiontoVisualStudio2010...................................................... ■
Chapter3:LayoutManagementinSilverlight ■
Chapter4:SilverlightControls.................................................................... ■
Chapter5:DataBindingandSilverlightListControls ■
Chapter6:SilverlightToolkit..................................................................... ■
Chapter7:DataAccessandNetworking ■
Chapter8:NavigationFramework.................................................................... ■
Chapter9:IsolatedStorageinSilverlight......................................................... ■
Chapter10:SystemIntegrationandDeviceSupport ■
Chapter11:IntroductiontoExpressionBlend ■
Chapter12:StylinginSilverlight................................................................. ■
■
Chapter14:CustomControls........................................................................ ■
CONTENTSATAGLANCE ■
Chapter15:PrintinginSilverlight................................................................ ■
Chapter16:Deployment............................................................................. ■ Index..............................................................................................
Contents
AbouttheAuthor................................................................................... Acknowledgments....................................................................................
Chapter1:WelcometoSilverlight4................................................................ ■
TheEvolutionoftheUserInterface................................................................ WhatIsSilverlight?..........................................................................................................
Cross-Platform/Cross-BrowserSupport.......................................................................................... UseofFamiliarTechnologies..................................................................................................
TheSilverlightDevelopmentEnvironment............................................................ ImprovedPerformance..........................................................................................................
Summary.......................................................................................................................
■ CONTENTS
■
Chapter2:IntroductiontoVisualStudio2010......................................................
What’sNewinVisualStudio2010?..................................................................
SupportforMultipleMonitors.................................................................................................
ExtensionManager.............................................................................................................
BuildingYourFirstSilverlightApplicationinVisualStudio
TryItOut:HelloWorldinSilverlight4......................................................................................
Summary.......................................................................................................................
■
Chapter3:LayoutManagementinSilverlight
TheCanvasPanel...................................................................................
TryItOut:UsingtheCanvasPanel............................................................................................
TheStackPanelControl..............................................................................
TryItOut:UsingtheStackPanelControl......................................................................................
TheGridControl..............................................................................................................
TryItOut:UsingtheGridControl............................................................................................
TheWrapPanelControl..............................................................................
TryItOut:UsingtheWrapPanelControl.......................................................................................
TheDockPanelControl...............................................................................
TryItOut:UsingtheDockPanelControl.......................................................................................
Summary.......................................................................................................................
CONTENTS ■
Chapter4:SilverlightControls.................................................................... ■
SettingControlProperties......................................................................... AttributeSyntax.............................................................................................................. Type-Converter-EnabledAttributes.............................................................................................
NestingControlsWithinControls................................................................... TryItOut:DeclaringanEventinXAML........................................................................................
TheBorderControl................................................................................. TryItOut:WorkingwiththeTextBoxControl..................................................................................
ExtendedControls.................................................................................. AddinganExtendedControl....................................................................................................
Summary....................................................................................................................... ■
DataBinding.................................................................................................................. TheBindingClass.............................................................................................................
ElementtoElementBinding......................................................................... TryItOut:ElementtoElementBinding........................................................................................
TheDataGridControl............................................................................... TryItOut:BuildingaSimpleDataGrid........................................................................................ TryItOut:BuildingaDataGridwithCustomColumns................................................
CONTENTS ■
TheListBoxControl................................................................................
DefaultandCustomListBoxItems..............................................................................................
NewDataBindingFeaturesinSilverlight4.........................................................
DataBindingandStringFormatting............................................................................................
Summary.......................................................................................................................
■
OverviewoftheSilverlightToolkit................................................................
InstallingtheToolkit........................................................................................................
ToolkitControls..............................................................................................................
Accordion.....................................................................................................................
AutoCompleteBox....................................................................................
TabControl....................................................................................................................
ViewBox.......................................................................................................................
TryItOut:UsingtheModalChildWindow......................................................................................
Summary.......................................................................................................................
■
DataAccessinSilverlightApplications............................................................
TryItOut:AccessingDataThroughaWCFService..............................................................................
AccessingServicesfromOtherDomains..............................................................
Summary.......................................................................................................................
■ CONTENTS
■ Chapter8:NavigationFramework....................................................................
TryItOut:CreatingaSilverlightNavigationApplication..................................................................... BenefitsoftheNavigationFramework...............................................................
DeepLinking.................................................................................................................. TheNavigationServiceObject.......................................................................
TryitOut:UsingtheNavigationServiceObject................................................................................ PassingDatatoNavigationPages...................................................................
TryitOut:PassingDatatoNavigationPages.................................................................................. UriMapping...................................................................................................................
TryitOut:UriMappingandtheNavigationFramework............................................... SilverlightNavigationApplicationTemplate........................................................
TryitOut:UsingtheSilverlightNavigationApplicationTemplate UsingMultipleFrames..............................................................................
TryitOut:UsingMultipleFrames............................................................................................. Summary.......................................................................................................................
■ Chapter9:IsolatedStorageinSilverlight.........................................................
UsingtheIsolatedStorageAPI................................................................................................ ManagingIsolatedStorage..........................................................................
ViewingandClearingIsolatedStorage......................................................................................... Summary.......................................................................................................................
CONTENTS ■
Chapter10:SystemIntegrationandDeviceSupport
■
Notification(Toast)API...........................................................................
TryItOut:ImplementingToastNotifications..................................................................................
Webcam/MicrophoneAccess...........................................................................
TryItOut:AccessingaUser’sWebCameraandMicrophone...........................................
WorkingwithCapturedStreams......................................................................
TryItOut:ExecutinganEXE..................................................................................................
DroppingFilesonaSilverlightApplication........................................................
DropEvent....................................................................................................................
Summary.......................................................................................................................
■
KeyFeaturesinExpressionBlend...................................................................
VisualXAMLEditor.............................................................................................................
Split-ViewMode...............................................................................................................
World-ClassTimeline..........................................................................................................
ExploringtheWorkspace............................................................................
Toolbox.......................................................................................................................
PropertiesPanel..............................................................................................................
CONTENTS ■
LayingOutanApplication WorkingwiththeGridControlinExpressionBlend.............................................................................
Summary....................................................................................................................... ■
InlineProperties............................................................................................................. TryItOut:SettingInlinePropertieswithVisualStudio......................................................................
SilverlightStyles............................................................................................................ TryItOut:UsingStylesAsStaticResources.................................................................................. MergedResourceDictionaries.................................................................................................. InheritingStylesUsingBasedOn...............................................................................................
Summary....................................................................................................................... ■
IntroductiontoSilverlightAnimation.............................................................. SilverlightStoryboards.......................................................................................................
ProgrammaticallyControllingAnimations............................................................ ViewingaStoryboardintheExpressionBlendTimeline
CreatingTransformationsinSilverlight............................................................ TransformationTypes..........................................................................................................
Summary.......................................................................................................................
■ CONTENTS
■
Chapter14:CustomControls........................................................................
SilverlightControlModel..........................................................................
PartsandStatesModel........................................................................................................
CreatingCustomControlsinSilverlight............................................................
ImplementingCustomFunctionality.............................................................................................
Summary.......................................................................................................................
■
Chapter15:PrintinginSilverlight................................................................
TryItOut:ImplementingSimplePrinting.......................................................................................
PrintingCustomContent............................................................................
TryItOut:ImplementingaCustomPrint.......................................................................................
AdditionalPrintingCustomization..................................................................
TryItOut:HandlingtheBeginPrintandEndPrintEvents............................................
Summary.......................................................................................................................
■
Chapter16:Deployment.............................................................................
XAPFiles.....................................................................................................................
ApplicationLibraryCaching........................................................................
TryItOut:ExploringAssemblyCaching........................................................................................
FullScreenPinning................................................................................
■ CONTENTS
OutofBrowserSupport............................................................................. CustomizingtheInstallApplicationDialog.................................................................................... RemovingInstalledApplications...............................................................................................
ElevatedTrustApplications........................................................................ Index..............................................................................................
About the Author
RobertLairbeganworkingwith.NETtechnologiesbeforeits
■
alpha,andhebuilttheoriginalIBuySpye-commerceandportal applicationsMicrosoftusedtointroduceASP.NETtothe developmentcommunity.Robertspecializesinanumberof technologies,includingSilverlight,mainframemodernizationto .NET,ASP.NETcustomapplicationdevelopment,SharePoint developmentandintegration,andmanyothers.Today,Robert worksasthedevelopmentmanageratT3Technologies (mpanythatoffersmainframe alternativesontheWindowsplatform.Hehaswrittenmanybooks andmagazinearticles,includingBeginningSilverlight3(Apress, 2009),andhasalsobeenaspeakeratanumberof.NETtechnical conferences.Followhimontwitterat com/robertlairandonthewe
About the Technical Reviewer
FabioClaudioFerracchiatiisaseniorconsultantandanalyst/developerofMicrosofttechnologies
■
whoworksfortheItalianbranchofBrainFo).HeisbothaMicrosoft CertifiedSolutionDeveloperandaMicrosoftCertifiedApplicationDeveloperfor.NET,aswellasa MicrosoftCertifiedProfessional.Fabioisalsoaprolificauthorandtechnicalreviewer.Overthepast10 years,he’swrittenarticlesforseveralinternationalmagazinesandcoauthoredmorethan10booksona varietyofcomputertopics.
Acknowledgments
IwouldliketothankthemanypeopleatApresswhomadethisbookhappen—especiallyDebraKelly, EwanBuckingham,DominicShakeshaft,andFabioClaudioFerracchiati.Withoutallofyourhardwork, thisbookwouldneverhavecomeabout.Thankyouall!
Thanksalsotomylovingwife,Debi,forherpatiencewhileIwrotethisbook.ToooftenIlefther alonetotakecareofoursonandtokeepourhousemaintained.Thankyouforbeingsuchawonderful wife.Iwouldalsoliketothankmyson,Max,forunderstandingwhenDaddycouldn’tplaybecausehe hadtowrite.
Iwouldalsoliketothankourgreatneighbors,whohaveprovidedmewithgreatfriendshipand support.Wehavebeenblessedwithanawesomestreetfilledwithwonderfulpeople.Inparticular,I’d liketothankMikeandConnieVandermarkforprovidingthevolleyballcourtweallenjoysomuch, GeorgeMullerforhostingSci-FiFridayeveryweek,andJimandStephanieSurianofornotonlybeing greatneighborsbutalsoincrediblefriendstomyfamily.
Finally,Iwanttogiveashoutouttomyonlinegamingfriends,KristenLudec,SamWrich,andSam Transue.Thoughweonlyknoweachotheronline,IvalueyourfriendshipandIthankyouforyour companionshipandsupportoverthelastfewyears.
Introduction
TherearemanywaystolearnanewtechnologysuchasSilverlight.Forstarters,Microsofthasgotten betterandbetterwiththedocumentationitreleaseswithitsprogrammingtechnologies,andemployee blogsandtechnologysitessuchasupplementingthat documentation.Moreover,youcangetinformationatanumberofwidelyusedforumswheremany expertsparticipate,and,ofcourse,youcanalwayspurchasetrainingifyouhavethecashflowtojustify it.Whileallofthesearegreatoptions,manypeoplestillliketopurchaseabookonthetechnology.But withsomanybooksonthemarket,howdoyouknowwhichisbest?
Myownphilosophyaboutlearninganewtechnologyisthatthereisnobetterwaythantoactually tryitoutforyourself.That’swhyIwroteBeginningSilverlight4inC#asanumberofstep-by-step,walk- throughtutorialsthatgiveyouhands-onexperiencewiththedifferenttopicsandgetyoustarted developingSilverlightapplicationsonyourown.
WhoShouldReadThisBook
ThisbookisforapplicationdeveloperswhowanttogetstartedwithSilverlight4.Itassumesyouhave someexperiencedevelopingapplicationsusingtechnologiesrelatedtoMicrosoft’sVisualBasic,ASP,or .NET,andhaveworkedwithMicrosoftVisualStudio.YoushouldbefamiliarwithJavaScript,C#,and
XML.
HowThisBookIsOrganized
EachchapterfocusesonaparticularareaofSilverlightandcontainsoneormore“TryItOut”exercises thatletyouapplywhatyou’velearned.Here’sbriefguidetowhatyou’llfindineachchapter:
- Chapter1,“WelcometoSilverlight4,”introducesyoutoRIAsandSilverlight.
You’llalsolearnaboutthetoolsusedindevelopingSilverlight-enabled applications.
- Chapter2,“IntroductiontoVisualStudio2010,”presentsVisualStudio2010and theimportantnewfeaturesitoffers.Inthischapter,you’llbuildyourfirst Silverlightapplication.
- Chapter3,“LayoutManagementinSilverlight,”discussesSilverlight’sflexible layoutmanagementsystem,whichletsyouspecifyhowcontrolswillappearin yourapplications.You’llfindin-depthdescriptionsofSilverlight’slayout managementcontrols.
- Chapter4,“SilverlightControls,”introducesthecommoncontrolsthatare providedwithSilverlight.You’llworkwiththesecontrolsthroughoutthebook.
INTRODUCTION ■
- Chapter5,“DataBindingandSilverlightListControls,”delvesintotheSilverlight controlsthatdisplaylistsofdata,andlooksathowtobinddatatothesecontrols. You’llseethatthesecontrolsareflexibleandcanshowdatainuniqueways.
- Chapter6,“SilverlightToolkit,”discussestheSilverlightToolkit,anopensource projectthatextendstheSilverlightcontrolsettoincludeanumberacontrols, themes,andframeworksthatcanhelpyoubemoreproductiveasaSilverlight developer.
- Chapter7,“DataAccessandNetworking,”describeshowdataaccessinSilverlight applicationsworkscomparedwithtraditionalapplications.Itthenexplores mechanismsforaccessingdatainSilverlightapplications,focusingontheuseof webservices.
- Chapter8,“NavigationFramework,”looksatbuildingSilverlightapplicationsthat allowuserstonavigatethroughdifferentpages,creatinganexperiencesimilarto browsingthroughdifferentpagesofawebsite
- Chapter9,“IsolatedStorageinSilverlight,”coverslocalizedstorageinSilverlight, whichishandledbyitsisolatedstoragefeature.You’lllearnhowtostoreuser- specificdataforyourapplicationandhavethatdatapersistoverbrowser instances.
- Chapter10,“SystemIntegrationandDeviceSupport,”covershowSilverlight applicationscansupportnotifications,integratewithlegacyCOMapplications andlibraries,accesstoauser’swebcameraandmicrophone,andbeenabledasa droptarget.
- Chapter11,“IntroductiontoExpressionBlend,”getsyoustartedwithMicrosoft
ExpressionBlend,whichletsyoueditXAMLdocumentsvisually.
- Chapter12,“StylinginSilverlight,”describeshowyoucancontrolthestylesof yourSilverlightapplication’suserinterfaceelements.You’llseehowtodefine stylepropertiesinlineusingbothVisualStudioandExpressionBlend,aswellas howtouseSilverlightstyles.
- Chapter13,“TransformationsandAnimation,”showsyouhowtocreate animationsinSilverlight.You’llseehowExpressionBlendhelpsyoucreate complexanimationsandtransformations.
- Chapter14,“CustomControls,”explainsthebasicsofcreatingcustomcontrolsin
Silverlight.You’lllearnwhenit’sappropriatetowritecustomcontrolsin Silverlight,andhowtobuildacustomcontrolthathasseveraldifferentstates.
- Chapter15,“PrintinginSilverlight,”discusseshowtoaddprintingfunctionalityto
Silverlightapplications.
- Chapter16,“Deployment,”coversthedeploymentandconfigurationofSilverlight applications,aswellashowtoenableout-of-browsersupport.
Bythetimeyoufinishthisbook,you’llhaveafirmfoundationinSilverlight,andyou’llbeableto createyourownSilverlight-enabledapplications.
C H A P T E R 1 ■ ■ ■ Welcome to Silverlight 4
ThischapterintroducesSilverlight,aMicrosoftcross-browser,cross-platformplug-inthatallowsyouto createrichinteractive(orInternet)applications(RIAs)fortheWeb.Itbeginswithabrieflookatthe evolutionofuserinterfaces,andthenprovidesanoverviewofSilverlight.You’lllearnhowSilverlightfits intoRIAsolutions,thebenefitsitbringstodevelopers,andthetoolsinvolvedindevelopingSilverlight- enabledapplications.
TheEvolutionoftheUserInterface
Softwareuserinterfacesareconstantlyevolvingandimproving.IrememberbackwhenIwasstill workingwithanearlyversionofWindowsandlookingatMacOSwithenvy.Then,Irememberseeing Linuxsystemswithradicalnewdesktopinterfaces.Morerecently,Ifoundmyselflookingagainatthe MacOSXDock(seeFigure1-1)andwantingthatformyWindowsXPmachine—tothepointwhereI purchasedaproductthatmimickedit.IwasdedicatedtoWindowsthroughitall,butIwasenviousof someoftheuserexperiencesthedifferentenvironmentsoffered.
Figure1-1.TheMacOSXDockfeature
TheevolutionoftheuserinterfacecontinuesintheWindowsoperatingsystem.Perhapsthemost prominentdifferencebetweenWindows7andpreviousversionsofWindowsisuserinterface improvements.Microsoftwasveryintentionalonimprovingtherichnessoftheoperatingsystem.One exampleisthenewtaskbar,wherelargeiconsreplacethetextdescriptionsandwhentheuserplacesthe cursoroveraniconwilldisplayawindowthumbnail,asshowninFigure1-2.
CHAPTER1 WELCOMETOSILVERLIGHT4
■ Figure1-2.Windows7improvedtaskbar
AnotheruserinterfaceimprovementinWindows7istheAeroSnap.Thisfeatureallowsyoutoeasily maximizeyourwindowbydraggingittothetopofthescreen,butitalsoallowsyoutodragthewindow totheleftorrightedgeofthescreeninordertotilethewindowto50%oftheleftorrightsideofthe screenasshowninFigure1-3.
Figure1-3.Windows7AeroSnapfeature
Thesefeaturesreflecthowoperatingsystemshaveevolvedovertheyears,butthesameevolution pertainstoallareasofdevelopment,andforjustaboutallindustries.Itisnowexpectedthatapplications notonlycontainnecessaryfeatures,butthattheyalsohaveslickuserinterfaces.However,whilerich applicationsarenowexpected,itisnotnecessarilythepriorityfordevelopers.Overthelastdecade, therehasbeenastruggletofindtherightbalanceof“rich”and“reach”inapplications.Ifyouconsider standarddesktopapplications,theapplicationsareinstalledonindividualclientmachines.Theyallow forveryrichandresponsiveuserinterfacesandadditionalfeatures,suchasofflinesupport.Performance oftheapplicationdependsonthemachineonwhichitisinstalled.Whiledesktopapplicationshavea
CHAPTER1 WELCOMETOSILVERLIGHT4
■
veryrichexperience,theyhaveverysmallreach.Theapplicationneedstohaveacodebaseforeach targetplatform,andeverymachineneedstohavetheapplicationinstalledandmaintained. Incontrast,wehavewebapplications,whichareHTML-focusedprogramsdesignedtorunwithina browserandacrossplatforms.FortheMicrosoft-baseddeveloper,thishasrecentlymeantdeveloping withASP.NETandbuildingwebservicestoofferservicesovertheInternet.Thefocusofmostofthelogic andcodehasbeenplacedontheserverforthebenefitofapplicationperformance.Thepricehasbeena pooruserinterface.Theseapplicationshadexcellentreach,buttheywerenotveryrich,asshownin Figure1-4.Betweenthesetwoextremesthereisacleargapbetweenthetechnologies.
Figure1-4.Richandreachapplicationcomparison
Tofillthisgap,anewdevelopmentapproachhassurfaced,asshowninFigure1-5.Thisnew approachistermedRIA(RichInternetApplications),whichisdefinedasawebapplicationthathasthe featuresandfunctionalityfoundintraditionaldesktopapplications.AlthoughthereareanumberofRIA technologies,includingMicrosoft’sSilverlight.
Figure1-5.RIAfillsthegapbetweenrichandreachapplications
CHAPTER1 WELCOMETOSILVERLIGHT4
■ RichInternetApplicationSolutions
TheconceptofRIAhasbeenaroundforquitesometime,butthetermrichInternetapplicationwasfirst usedin2002inaMacromediawhitepaper.Beforethen,thetermsremotescriptingandXInternetwere usedtodescribetheconcept.
Today,manydifferentsolutionsfitthedescriptionofRIAs,butthereisoneconsistentcharacteristic: allRIAsolutionsinvolvearuntimethatrunsontheclientmachineandarchitecturallysitsbetweenthe userandtheserver.
Inrecentyears,thetechnologythatismostcommonlyusedinRIAsisFlash.WhenFlashwas introduced,itbroughttotheWebrichuserexperiencesneverseenbefore.However,duetothelackof toolsallowingMicrosoft.NETdeveloperstointegrateFlashintotheirapplications,tothosedevelopers Flashjustseemedlikeatoolforaddingsomeprettyeffectstoawebpage,butnothingfunctional.
ThenawonderfulthinghappenedwhenAdobepurchasedMacromedia.Allofthesudden,Flash wasmarriedtosomeofthedevelopmenttoolsofferedbyAdobe.Microsoftretaliatedbyannouncing Silverlight,formerlyknownasWindowsPresentationFoundationEverywhere(WPF/E).Silverlightisthe technologythatmany.NETdevelopershavebeenwaitingfor.
WhatexactlyisSilverlight?And,whatimpactdoesSilverlightactuallyhaveonusas.NET developers?Well,I’mgladyouasked.
WhatIsSilverlight?
AsIexplainedintheprevioussection,allRIAshaveonecharacteristicincommon:aclientruntimethat sitsbetweentheuserandtheserver.InthecaseofMicrosoft’sRIAsolution,Silverlightisthisclient runtime.Specifically,Silverlightisacross-platform,cross-browserplug-inthatrendersuserinterfaces andgraphicalassetsonacanvasthatcanbeinsertedintoanHTMLpage.
ThemarkupusedtodefineaSilverlightcanvasiscalledExtensibleApplicationMarkupLanguage (XAML,pronounced“zammel”).XAMLisanXML-basedlanguagethatissimilartoHTMLinsomeways. LikeHTML,XAMLdefineswhichelementsappear,aswellasthelayoutofthoseelements.However, unlikeHTML,XAMLgoesfarbeyondsimpleelementdefinitionandlayout.UsingXAML,youcanalso specifytimelines,transformations,animations,andevents.
ThefollowingisanexampleofaSilverlightcanvasdefinedinXAML:
<UserControl x:Class="FirstLookXaml.MainPage" Width="640" Height="480">
<Canvas x:Name="LayoutRoot" Background="White"> <Rectangle Height="119" Canvas.Left="75" Stroke="Black" Canvas.Top="92" Width="183"/> <Ellipse Height="119" Canvas.Left="347" Stroke="Black" Canvas.Top="92" Width="189"/> <Button Content="XAML Rocks!" Height="43" Canvas.Left="233" Canvas.Top="285" Width="161"/> </Canvas>
</UserControl>
CHAPTER1 ■
WELCOMETOSILVERLIGHT4
Figure1-6showsthiscanvasinMicrosoftExpressionBlend,thedesigntoolusedtoeditandcreate