58
CPSC 481 – Tutorial 10 Expression Blend Brennan Jones [email protected] (based on tutorials by Bon Adriel Aseniero and David Ledo)

CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CPSC481– Tutorial10ExpressionBlend

[email protected]

(basedontutorialsbyBonAdrielAseniero andDavidLedo)

Page 2: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ExpressionBlend

• Enablesyoutobuildrichandcompellingapplicationsforthedesktopandweb.• Enablesyoutotakefulladvantageoftheunderlyingpoweroftheplatform.• Rapidprototypingwithoutwritingcode• 3Dtransformations• Pixeleffects(blur,glow,ripple,etc.)• Animation

• Visually editthetemplateofacontroleasilyonthedesignsurface,redesigningittoperfectlyfulfillthefunctionitwillplaywithinanapplication.

Page 3: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

BasicIdea

• DesignyourinterfaceinExpressionBlend• CodethelogicandinteractioninVisualStudio

Page 4: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

StartingExpressionBlend

Page 5: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

StartingaProject

• ClickonNewProject ifyouwanttostartaprojectdirectlyinExpressionBlend.• Choosethisoneforthistutorial.

• ClickonOpenProject ifyouwanttouseanexistingproject(whichmayhavebeencreatedinVisualStudio).

Page 6: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

StartingaProject

• SelectWPFApplication• Nameit• HitOK

Page 7: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

TheInterface

Project/Solutionviewer

Page 8: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

TheInterface

Tools

Page 9: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Tools

Page 10: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

TheInterface

“DrawingBoard”

Page 11: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

TheInterface

ObjectsandTimeline“Layers”

Page 12: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Objects

• ThisiswhereyouseeyourVisuals• Arrangedasareversedstack

• Visualsonthebottomareontop• AlsotrueforVisualsinsideContainerswhichareinsideanotherContainer

• ThinkLayers andGroups

Page 13: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

TheInterface

ObjectProperties

Page 14: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Properties

Selectingavisualhere… …bringsupthatvisual’spropertiesinhere.

Page 15: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Properties

• BrushesProperties• Usedtoeditthebackgroundfill,borderstroke,opacity,etc.ofavisual• UsesRGBandalphavaluesorthehexvalueofacolour• Niceresourcefornamedcolours:http://cloford.com/resources/colours/500col.htm

Page 16: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Properties

• Appearance• Usedtochangetheappearanceofavisualbysettingitsvisibilityandopacity,oraddingeffectstoitsuchasblurordropdownshadows

Page 17: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Properties

• Layout• Usedtochangehowthewindowwillappearonthescreen,orhowavisualwillflowwithothervisualsinacontainer.• Usethistoeditsizes,positions,andalignments.

Page 18: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Properties

• Somepropertiesareonlyavailabletospecifictypesofvisuals.• E.g.,onlywindowscanhaveaniconpropertyorawindowstateproperty(maximized,minimized,etc.).

• ThesepropertiescanbesetintheCodeBehindaswell.

Page 19: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Coding

ChooseView– SplitView

ToviewtheXAMLEditor

Page 20: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Coding

• YoucancodedirectlyinExpressionBlend,BUT itishighlysuggestedtouseVisualStudioinparallelwithitforcoding.• Why?

• BecauseyougainaccesstoVisualStudio’srichsetoftoolsforcoding(refactor,debugger,etc.).

• UseExpressionBlendfordesigningtheGUI,useVisualStudiotocodethelogic.

Page 21: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

HandsOn

• Wewillcreateapictureviewer applicationusingExpressionBlendandVisualStudio.• Functionalities:

1. Homescreen2. Pagetoseeallphotos3. Vieweachphoto

Page 22: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

PicturO

Page 23: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Window

Selectthewindow Changeitswidth&heightto800x600

Page 24: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Window

ChangetheBackgroundcolourto#FF353535

Select‘Background’

Page 25: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Window

WindowStyle =None

ResizeMode =NoResize

Title=“PicturO”

Page 26: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Window

• Renamethegridcontainedinthewindowto‘MainGrid’.• Insertanewgridwithinit,callit‘SplashGrid’.

Page 27: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Grids

• ForboththeMainGrid andSplashGrid:• Setthewidthandheightto‘Auto’• SettheHorizontalAlignment andVerticalAlignment to‘Stretch’

Page 28: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

StartScreen

Page 29: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Startscreen

• Path:BackgroundShape• TextBlock:P• TextBlock:AppTitle• Button:ViewPhotosButton

• Button:ExitButton• Button:MinimizeButton

Page 30: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Animation

• CanbedoneinC#WPFusingStoryboards.• CanalsobedoneeasilyusingExpressionBlend.

Page 31: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Animation

Onthe“Object&Timeline”tab,click+

ThiswilladdaStoryboardResource

Page 32: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Animation

• AstheAnimationstartstorecord…• EditaVisual’spropertyatastartingtime thenaddanewKeyframe totheendingtime andputinthenewvalueoftheproperty.

Page 33: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Controls

• VisualssuchasButtons,Containers,andShapesarecalledControls.• Theyhaveanunderlyingtemplate specifyinghowtheyshouldlook.• Thetemplateiscustomizable.

Page 34: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CustomButton

• AddaButton toyourwindow• Rightclick->EditTemplate->CreateEmpty• Callit‘TileButton’• Youcanthenapplythistemplatetootherbuttonslateron

Page 35: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CustomButton

• GoodInterfacesshouldberesponsive,soletusaddfeedbacktoourcustombuttonwhenitgetshoveredover.• Addthese:

• Cover: Atransparentrectangleontopofthebutton• Content:Thecontent(text)presenter• HoverColor: Thecolouredrectanglethatshowsupwhenthebuttongetshoveredover

Page 36: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CustomButton

• OntheTriggers tab,addtheIsMouseOver =true event• Thismeansthateverytimethemouseisoverourbutton,theanimationwillbetriggered

Click‘+Property’

Changethesecondandthirddropdownsto:‘IsMouseOver’and‘True’respectively

Page 37: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CustomButton

• OnthefirstrowundertheActivatedwhen tab,selectgrid onthefirstdropdownbox

Page 38: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CustomButton

• Click+ontheActionswhenactivatingtab• AddanewStoryboard• TheStoryboardwillthenstartrecording

Page 39: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

CustomButton

• Nowourbuttongivesusfeedback• AddaneventtoitthatclosestheappinVisualStudio• ExitButton.Click• this.Close();

Page 40: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ApplyingourTemplate

• Addaminimizebuttontoourapp(ifnotalreadythere)• Rightclickonthebutton->EditTemplate->ApplyResource->chooseyourtemplate• Addaneventtoit

• MinimizeButton.Click• this.WindowState =WindowState.Minimize

Page 41: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Photos

Page 42: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Createanewgrid

• Thisiswherewewillshowourphotos• IthasaScrollViewer thathasaUniformGridinsideofitcalledPhotoViewerGrid

Page 43: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Visibility

• SeparateourdifferentviewsintoGrids(ifnotalreadydone)• IfSplashGrid isvisible,thenPhotoGrid shouldbehidden,andviceversa

Page 44: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

PhotoTile

• Here,wewillneedtoloadphotosintotileswhichwecallPhotoTiles• CreateaGrid,andinsideit,addanImage controlandaTextBlock• TheImagecontrolwillcontainourphoto• TheTextBlock willcontainthetitleofthephoto

Page 45: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

PhotoTile

• Great!WenowhaveaPhotoTile• Butwait…Dowereallywanttodothisforeveryphotowehave?• No!

• UseUserControls

Page 46: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

UserControls

• User-definedControls(e.g.,CommentBox)thatcanbeusedastemplates withinaproject.• Usefulforwhenyouhavemultiplethingsthatshouldlookthesamebuthavedifferentcontent.

Page 47: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

PhotoTile

• RightclickandturnourPhotoTile gridintoaUserControl• Wecannowreuse itformanyphotos!

Page 48: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

LoadingPhotos

OntheCodeBehind…• CreateaClasscalledPhotoDB• ThisclasswillhaveaLoadPhotos methodandwillcontainallofthepathstoourphotosinastringarray

Page 49: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

LoadingPhotos

InPhotoDB.cs:class PhotoDB{

private string[] photos = { };public string[] Photos {

get {return this.photos;

}}

public void LoadPhotos(string path) {try {

photos = System.IO.Directory.GetFiles(path);}catch (Exception) {

// Do nothing}

}}

Page 50: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

LoadingPhotos

• WewillthenaccessthephotosinthisclassandcreatePhotoTileControlsforeachofthem,thenaddthemtothePhotoViewerGrid

Page 51: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ViewingaPhoto

Page 52: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ViewingaPhoto

• Again,wewillcreateaUserControl forthis• StartwithdrawingagridthathasTextBlock,anImage control,andaStackPanel forcomments• TurnitintoaUserControl calledPhotoPageControl

Page 53: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ViewingaPhoto

• GotothecodewherewecreateeachPhotoTileControl andsubscribetoitsMouseDownevent

Addthis

Page 54: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ViewingaPhoto

• Collapsealloftheotherviews• CreateaninstanceofthePhotoPageControl andpopulateitwiththedatafromthePhotoTileControl

Page 55: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ViewingaPhoto

• Now,clickingonaPhotoTile willopenupaphotopage.• Butwe’restuck!Wecan’tgobacktothephotolistfromthephotopage.• SolvethisbyaddingabackbuttoninsidethePhotoPageControl.

Page 56: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

ViewingaPhoto

Page 57: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Extendingthis…

• ToallowforcommentswithinthePhotoPageControl,createaCommentBoxUserControl thathasTextBlocks forthenameofcommenterandthecomment,andadeletebutton.• AddTextBoxes sothatwhensomeonetypesonitandpressesEnter(orasendbutton),itwillgenerateaCommentBox withtherespectivedatafromtheTextBox fields.• AppendtheCommentBox toaScrollableStackPanelwithinthePhotoPageControl.

Page 58: CPSC 481 –Tutorial 10pages.cpsc.ucalgary.ca/~li26/481/slides/w09.pdf · 2017-03-16 · applications for the desktop and web. •Enables you to take full advantage of the underlying

Extendingthis…

• NO! Youcannotsubmitthisexampleappasyourproject.• Youmay reusecodefromthisexample,aslongasyoucite it.• Hopeyoulearned somethingnew!