iedotnetug silverlight class week 6

16
Silverlight 4 Course 1.Introduction to Silverlight 2.Layout 3.Input Handling 4.Applications, Resources, Deployment 5.Data Binding, View Model 6.Out of Browser, File Access, Printing 7.WCF RIA Services (4 Weeks )

Upload: iedotnetug

Post on 24-May-2015

370 views

Category:

Technology


1 download

DESCRIPTION

Slides from the Inland Empire .NET User's Group Silverlight class

TRANSCRIPT

Page 1: IEDOTNETUG Silverlight Class Week 6

Silverlight 4 Course

1. Introduction to Silverlight

2. Layout

3. Input Handling

4. Applications, Resources, Deployment

5. Data Binding, View Model

6. Out of Browser, File Access, Printing

7. WCF RIA Services (4 Weeks )

Page 2: IEDOTNETUG Silverlight Class Week 6

Silverlight Week 6

Agenda 

1.Out of Browser2.Printing3.File Access4.IsolatedStorage5.ClassProject

Page 3: IEDOTNETUG Silverlight Class Week 6

Out of Browser• Out of Body Experience ?

• SL started as plugin for Media.

• SL 3 allowed OOB. Partial Trust.

• Allows your app to work offline without Internet connectivity.

• SL 4 enhanced OOB. Allowed Elevated Trust.

• Elevated Trust allows :

– Access to local file system.

– COM Automation in Windows Systems.

– Sizing and moving of windows, custom window chrome

– Full screen means better media experience, more desktop pixels.

Notification API : Also called Toast.

SL provides API to check OOB mode, Network access, etc.

Page 4: IEDOTNETUG Silverlight Class Week 6

OOB + -• OOB does not have access to HTML DOM,

Browser Javascript, other in page assets.

• 25MB instead of 1MB. Can be increased by prompting user.

• Access to Function Keys F1,F2.

• Can be pinned to Start Menu or Task Bar in Windows 7.

• In browser provides automatic update whereas OOB needs an expicit check.

Page 5: IEDOTNETUG Silverlight Class Week 6

OOB Install/UnInstall• Right click and select in context menu.

• Or provide a button to install as OOB.

• Files gets copied to some location.

• No registry entries, admin rights, no DLLS needed.

• Just a prompt to specify Shortcut location.

• To uninstall : – Right click and say “Remove this App”

– Control Panel ‘s Add/Remove Programs.

Page 6: IEDOTNETUG Silverlight Class Week 6

OOB• Use OOB dialog from Project Settings to set the OOB settings.

Goes into OutofBrowserSettings.xml.

• API:

– Application.Current.Install() : installs it.

– Application.Current.InstallState

• Installed

• Installing : Probably install additional support files.

• Not Installed

• Install Failed

– Application.Current.IsRunningOutOfBrowser

Page 7: IEDOTNETUG Silverlight Class Week 6

DEMO• XAML :

– Grid1 : “Install” button.

– Grid2 : TextBlock : “Running out of browser”

– Both Grids collapsed.

• Code Behind

– Utility method :• If Current not installed uncollapse grid1.

• If Current is installed uncollapse grid2 and collapse grid1.

– Call install in Install handler

• DEMO : Can someone do it, please ?

• Call Install() from constructor. What happens ?

Page 8: IEDOTNETUG Silverlight Class Week 6

Install()

• What about Security ?– Rogue Silverlight apps could just call Install() in

constructor.

• Nope. You can call Install() only from UI event.

Page 9: IEDOTNETUG Silverlight Class Week 6

Printing

• Why do we need Printing ?

Page 10: IEDOTNETUG Silverlight Class Week 6

Printing•Create PrintDocument.•Attach to PrintPage event.

– Create PrintLayout and set the width/height to PrintPageEventArgs.PrintableArea.Width/Height.

– Set “PrintPageEventArgs.PageVisual” to any UI element. Nor necessarily one on the screen. If needed you can create a new one too.

– Set HasMorePages property to TRUE for subsequent pages.

•Call PrintDocument.Print(). Provide a title for the print job.

Page 11: IEDOTNETUG Silverlight Class Week 6

Printing

• Demo

• Bitmap printing.

Page 12: IEDOTNETUG Silverlight Class Week 6

File Access

• 3 options :

• 1. OpenFileDialog and SaveFileDialog : SL does not know the location of the file.

• 2. FileStream, StreamWriter : Elevated Trust

• 3. Isolated Storage.

Page 13: IEDOTNETUG Silverlight Class Week 6

Open/SaveFileDialog

• User interaction needed.

• User selects the file.

• OpenFileDialog has a multiSelect property to allow multiple selection.

• Demo.

Page 14: IEDOTNETUG Silverlight Class Week 6

Isolated Storage

• Per application.

• Better than Cookie. No 4K limit.

• 1MB limit. Can ask for more if needed.

• Works across Cross browser.

• IsolatedStorageFile.GetUserStoreForApplication

• IsolatedStorageFileStream

Page 15: IEDOTNETUG Silverlight Class Week 6

IsolatedStorageFile• System.IO.IsolatedStorage Name space.

– GetUserStoreForApplication()– GetUserStoreForSite() Not available in .Net Full– GetDirectoryNames() Supports Wild cards for pattern matching. Returns string[]– GetFileNames() Supports Wild cards for pattern matching. Returns string[]

– DeleteFile() Absolute path needed– DeleteDirectory() Absolute path needed– CreateDirectory()

– Quota & AvailableFreeSpace Properties– IncreaseQuotaTo() Total number of bytes to increase to and not delta

– Create IsolatedStorageFileStream() object to create new files. “filemode” enumerator.– Needs to be disposed of. So use “using”.

Page 16: IEDOTNETUG Silverlight Class Week 6

Class Project• Create a trusted app with 3 buttons : Create Dirs, Del Dir, Create File

and a textblock.• CreateDirs should create “Dir1/text1.txt” & “Dir2/text2.txt” and

“Dir2/text3.txt” and “Dir3/text4.txt”.• TextBlock should show the content of “Dir2/text3.txt”.• Del Dir should delete “Dir2”. Once deleted textblock should be empty.

Use binding. Also notify using toast.• Create File button should create “Dir2/text3.txt”. Use command to

enable/disable it.• Notify Button :

– NotificationWindow hello = new NotificationWindow()– Notify.height = notify.width = 100;– Nottify.Content = textblock;– Notify.Show(5000);