IEDOTNETUG Silverlight Class Week 6

527 views

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
527
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 1. Vector graphics Transform Animation HD Video   2. Binary compatible (XAP Files) No need to target separate platforms.   3. Multi language : C#, VB, IronPython, F#.   CLR is same.
  • IEDOTNETUG Silverlight Class Week 6

    1. 1. Silverlight 4 Course <ul><li>Introduction to Silverlight </li></ul><ul><li>Layout </li></ul><ul><li>Input Handling </li></ul><ul><li>Applications, Resources, Deployment </li></ul><ul><li>Data Binding, View Model </li></ul><ul><li>Out of Browser, File Access, Printing </li></ul><ul><li>WCF RIA Services (4 Weeks ) </li></ul>
    2. 2. Silverlight Week 6 <ul><li>Agenda   </li></ul><ul><li>Out of Browser </li></ul><ul><li>Printing </li></ul><ul><li>File Access </li></ul><ul><li>IsolatedStorage </li></ul><ul><li>ClassProject </li></ul>
    3. 3. Out of Browser <ul><li>Out of Body Experience ? </li></ul><ul><li>SL started as plugin for Media. </li></ul><ul><li>SL 3 allowed OOB. Partial Trust. </li></ul><ul><li>Allows your app to work offline without Internet connectivity. </li></ul><ul><li>SL 4 enhanced OOB. Allowed Elevated Trust. </li></ul><ul><li>Elevated Trust allows : </li></ul><ul><ul><li>Access to local file system. </li></ul></ul><ul><ul><li>COM Automation in Windows Systems. </li></ul></ul><ul><ul><li>Sizing and moving of windows, custom window chrome </li></ul></ul><ul><ul><li>Full screen means better media experience, more desktop pixels. </li></ul></ul><ul><li>Notification API : Also called Toast. </li></ul><ul><li>SL provides API to check OOB mode, Network access, etc. </li></ul>
    4. 4. OOB + - <ul><li>OOB does not have access to HTML DOM, Browser Javascript, other in page assets. </li></ul><ul><li>25MB instead of 1MB. Can be increased by prompting user. </li></ul><ul><li>Access to Function Keys F1,F2. </li></ul><ul><li>Can be pinned to Start Menu or Task Bar in Windows 7. </li></ul><ul><li>In browser provides automatic update whereas OOB needs an expicit check. </li></ul>
    5. 5. OOB Install/UnInstall <ul><li>Right click and select in context menu. </li></ul><ul><li>Or provide a button to install as OOB. </li></ul><ul><li>Files gets copied to some location. </li></ul><ul><li>No registry entries, admin rights, no DLLS needed. </li></ul><ul><li>Just a prompt to specify Shortcut location. </li></ul><ul><li>To uninstall : </li></ul><ul><ul><li>Right click and say “Remove this App” </li></ul></ul><ul><ul><li>Control Panel ‘s Add/Remove Programs. </li></ul></ul>
    6. 6. OOB <ul><li>Use OOB dialog from Project Settings to set the OOB settings. Goes into OutofBrowserSettings.xml. </li></ul><ul><li>API: </li></ul><ul><ul><li>Application.Current.Install() : installs it. </li></ul></ul><ul><ul><li>Application.Current.InstallState </li></ul></ul><ul><ul><ul><li>Installed </li></ul></ul></ul><ul><ul><ul><li>Installing : Probably install additional support files. </li></ul></ul></ul><ul><ul><ul><li>Not Installed </li></ul></ul></ul><ul><ul><ul><li>Install Failed </li></ul></ul></ul><ul><ul><li>Application.Current.IsRunningOutOfBrowser </li></ul></ul>
    7. 7. DEMO <ul><li>XAML : </li></ul><ul><ul><li>Grid1 : “Install” button. </li></ul></ul><ul><ul><li>Grid2 : TextBlock : “Running out of browser” </li></ul></ul><ul><ul><li>Both Grids collapsed. </li></ul></ul><ul><li>Code Behind </li></ul><ul><ul><li>Utility method : </li></ul></ul><ul><ul><ul><li>If Current not installed uncollapse grid1. </li></ul></ul></ul><ul><ul><ul><li>If Current is installed uncollapse grid2 and collapse grid1. </li></ul></ul></ul><ul><ul><li>Call install in Install handler </li></ul></ul><ul><li>DEMO : Can someone do it, please ? </li></ul><ul><li>Call Install() from constructor. What happens ? </li></ul>
    8. 8. Install() <ul><li>What about Security ? </li></ul><ul><ul><li>Rogue Silverlight apps could just call Install() in constructor. </li></ul></ul><ul><li>Nope. You can call Install() only from UI event. </li></ul>
    9. 9. Printing <ul><li>Why do we need Printing ? </li></ul>
    10. 10. Printing <ul><li>Create PrintDocument. </li></ul><ul><li>Attach to PrintPage event. </li></ul><ul><ul><li>Create PrintLayout and set the width/height to PrintPageEventArgs.PrintableArea.Width/Height. </li></ul></ul><ul><ul><li>Set “PrintPageEventArgs.PageVisual” to any UI element. Nor necessarily one on the screen. If needed you can create a new one too. </li></ul></ul><ul><ul><li>Set HasMorePages property to TRUE for subsequent pages. </li></ul></ul><ul><li>Call PrintDocument.Print(). Provide a title for the print job. </li></ul>
    11. 11. Printing <ul><li>Demo </li></ul><ul><li>Bitmap printing. </li></ul>
    12. 12. File Access <ul><li>3 options : </li></ul><ul><li>1. OpenFileDialog and SaveFileDialog : SL does not know the location of the file. </li></ul><ul><li>2. FileStream, StreamWriter : Elevated Trust </li></ul><ul><li>3. Isolated Storage. </li></ul>
    13. 13. Open/SaveFileDialog <ul><li>User interaction needed. </li></ul><ul><li>User selects the file. </li></ul><ul><li>OpenFileDialog has a multiSelect property to allow multiple selection. </li></ul><ul><li>Demo. </li></ul>
    14. 14. Isolated Storage <ul><li>Per application. </li></ul><ul><li>Better than Cookie. No 4K limit. </li></ul><ul><li>1MB limit. Can ask for more if needed. </li></ul><ul><li>Works across Cross browser. </li></ul><ul><li>IsolatedStorageFile.GetUserStoreForApplication </li></ul><ul><li>IsolatedStorageFileStream </li></ul>
    15. 15. IsolatedStorageFile <ul><li>System.IO.IsolatedStorage Name space. </li></ul><ul><ul><li>GetUserStoreForApplication() </li></ul></ul><ul><ul><li>GetUserStoreForSite()  Not available in .Net Full </li></ul></ul><ul><ul><li>GetDirectoryNames()  Supports Wild cards for pattern matching. Returns string[] </li></ul></ul><ul><ul><li>GetFileNames()  Supports Wild cards for pattern matching. Returns string[] </li></ul></ul><ul><ul><li>DeleteFile()  Absolute path needed </li></ul></ul><ul><ul><li>DeleteDirectory()  Absolute path needed </li></ul></ul><ul><ul><li>CreateDirectory() </li></ul></ul><ul><ul><li>Quota & AvailableFreeSpace Properties </li></ul></ul><ul><ul><li>IncreaseQuotaTo()  Total number of bytes to increase to and not delta </li></ul></ul><ul><ul><li>Create IsolatedStorageFileStream() object to create new files. “filemode” enumerator. </li></ul></ul><ul><ul><li>Needs to be disposed of. So use “using”. </li></ul></ul>
    16. 16. Class Project <ul><li>Create a trusted app with 3 buttons : Create Dirs, Del Dir, Create File and a textblock. </li></ul><ul><li>CreateDirs should create “Dir1/text1.txt” & “Dir2/text2.txt” and “Dir2/text3.txt” and “Dir3/text4.txt”. </li></ul><ul><li>TextBlock should show the content of “Dir2/text3.txt”. </li></ul><ul><li>Del Dir should delete “Dir2”. Once deleted textblock should be empty. Use binding. Also notify using toast. </li></ul><ul><li>Create File button should create “Dir2/text3.txt”. Use command to enable/disable it. </li></ul><ul><li>Notify Button : </li></ul><ul><ul><li>NotificationWindow hello = new NotificationWindow() </li></ul></ul><ul><ul><li>Notify.height = notify.width = 100; </li></ul></ul><ul><ul><li>Nottify.Content = textblock; </li></ul></ul><ul><ul><li>Notify.Show(5000); </li></ul></ul>

    ×