This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
class Car{ string Image {get;set} string Model {get;set]}
Databinding• Two way data binding from User interface to business objects• Notification via INotifyPropertyChanged• DataContext is inherited via Visual Tree
• From XAML• <TextBlock Text="{Binding Nasdaq.Points, Mode=OneWay}"/>
• From codeBinding binding = new Binding("Nasdaq.Points");binding.Mode = BindingMode.OneWay;TextBlock tb = new TextBlock();tb.SetBinding(TextBlock.TextProperty, binding);
DeepZoom• Navigates images of any size and resolution optimizing
network bandwidth and download size.• Seamless transitions as you zoom and pan.
• LINQ = Language INtegrated Query• Allows query expressions to benefit from compile-time syntax
checking, static typing & Intellisense• Works on any IEnumerable<T>-based source
• Supports querying of in-memory data sources• Other LINQ technologies forthcoming:
• XLINQ = LINQ for XML• DLINQ = LINQ for relational data
var filteredPlayers = from p in players where p.HomeRuns > 20 orderby p.HomeRuns descending select p;
Return all players with more than twenty home runs, sorted
Dynamic Language Run-time• Open Source engine and languages• Script Server (Chiron) for local development.• Debugging support
class App:def __init__(self):self.scene = Application.Current.LoadRootVisual("app.xaml")def start(self):self.scene.Message.Text = "Welcome to Silverlight and IronPython!"App().start()
class Appdef initialize@scene = System::Windows::Application.Current.LoadRootVisual "app.xaml"enddef [email protected]_name('message').text = "Welcome to Silverlight and IronRuby!" endend App.new.start
Import("System.Windows.Application")function App() { this.scene = Application.Current.LoadRootVisual("app.xaml") }App.prototype.start = function() {this.scene.Message.Text = "Welcome to Silverlight and Managed JScript!" }app = new App app.start()
• Basic profile• A few restrictions (e.g. SOAP Faults not supported)
• Asynchronous invocation• Follows cross-domain policy restrictions• Generated proxies support data binding
Sockets• TCP only• Asynchronous API• No explicit bind and no listen/accept support• Restricted ports ( 4502-4534)• For Beta1, site of origin only, cross-domain for RTW
void Connect(AddressFamily family){ SocketAsyncEventArgs connectArgs = new SocketAsyncEventArgs(); connectArgs.RemoteEndPoint = new DnsEndPoint( Application.Current.Host.Source.Host, 4502); connectArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnConnectCompleted); socket = new Socket(family, SocketType.Stream, ProtocolType.Tcp); if (!socket.ConnectAsync(connectArgs)) OnConnectCompleted(socket, connectArgs);}
Extending the Browser Sandbox(safely)
OpenFileDialog• Provides native OS experience• Sandboxed API returns safe filename and readable stream• Support for multiple files
Isolated Storage• Stream based access to a private file/directory structure• Patterned after .NET Framework IsolatedStorage classes• Read and write string or binary data• Store is per application XAP• Application code to request size increase
• User prompt to accept quota increase• Quotas fall into predetermined size slots• Code must initiate increase size call from within user input/event
-100% Free (as in free beer)-Full development experience (from data to Web Services to client UI todebugging)-Does not require Windows on the web server or on client OS
Silverlight Tools for Visual Studio 2008
Silverlight in the .NET platform
Silverlight and ASP.NET/AJAXIntegration
• Two ASP.NET server controls• Both ship in SDK: System.Web.Silverlight.dll• Deploys to /bin folder• Available at design-time within Visual Studio
• Corresponding AJAX types• Both server controls provide client-side Javascript types as well
Silverlight and WPF• Silverlight is a subset of WPF
• Plus a few extra web features and its own codecs• Reuse strategy
• Same skills• Same tools• Same XAML and UI• Silverlight code should run on WPF with minor changes
• Cross-platform & cross-browser plugin• Works with Safari, Firefox and Internet Explorer• Mac OS X and Windows• Any web server• Fast, easy install process
• Securely extends your web browser’s sandbox• Off-line storage, OpenFileDialog, Sockets, cross-domain
information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THISPRESENTATION.
Byte-range Seeking Support• Enables seeking to non-downloaded portions of a file stored
on *any* HTTP 1.1-enabled web server.• Win-win for content distributors and viewers
• Distributors save on bandwidth on non-viewed parts of media.• Viewers get smaller latencies when seeking.
• When Seek is called on the MediaElement• New byte-range request is made, if needed;• Silverlight keeps track of downloaded portions of the file;• Playback continues from new position.
• Supported almost everywhere.
Isolated Storage Quota
Microsoft Confidential
// Use application for storage scope (EG URL where application is fromwww.microsoft.com/silverlight/app.xap and any DLLs loaded into this app domain)IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();// The application knows it needs at least 5MB of isolated storage spaceint spaceNeeded = 524288; // = 512K in bytes// Check to see how much space is remainingif (isf.RemainingSize < spaceNeeded){ // Request more quota space. This call will not work if not called from a WPF event if (!isf.IncreaseQuotaTo(isoStore.Quota + spaceNeeded)) { // The host did not allow the quota increase, meaning we do not have // enough isolated storage space to do what we want; do not continue. return; }}// We have at least 512K of isolated storage space available.// Proceed with using it...// NOTE it is possible the host allocated more than 512K of space// ...// Find out what the new quota isDebug.WriteLine("New quota size " + isf.Quota.ToString() );
Isolated Storage Dictionary
• Dictionary access for settings• Wraps low level IsolatedStorage• Values are serialized using the WCF Data Contract serializer
Microsoft Confidential
LocalSettings localSettings = new LocalSettings();//Add key, value pairlocalSettings.Add(“Title”,”Programming in Silverlight”);//Add key,value using indexerlocalSettings [“Price”] = 15;//Add key, value using Set methodlocalSettings.Set(“Price”, 15);//Confirm is a key exists and then retrieve its valueif(localSettings.Contains(Title)) title = (string) localSettings[“Title”];//Remove key from storelocalSettings.Remove(“Price”)// Explicitly commit settings. Also committed when object goes out ofscopelocalSettings.Save();
WebClient
• Easy to use, events-based async• Download string, stream• Progress information
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadCompleted);webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
• Expose managed properties/methods/events to Javscript• ScriptableType and ScriptableMember indicate managed
entry points on a type• HtmlPage.RegisterScriptableObject
• Name of the scriptable entry point• Managed instance that backs the entry point
• Scriptable entry points are exposed off the Content propertyof your Silverlight control.• myControl.Content.CustomName.SomeManagedPropertyOrMethod
Working with HTML/Javascript• Scriptable type interoperability
• Primitive types marshal by-value in both directions• Complex managed types are returned by-reference to Javascript• Javascript types usually must be copied into equivalent managed
types prior to being passed in to managed code.• Uses JSON serialization
• Can pass Javascript types by-reference as instances ofScriptObject
Working with HTML/Javascript• Scriptable type interoperability
• Can return HtmlWindow, HtmlDocument and HtmlElementinstances directly to Javascript
• Managed arrays act like Javascript arrays• Custom managed types act like Javascript objects• Custom managed dictionaries also act like Javascript objects
• Converting Javascript object graphs to managed objects:• Use createManagedObject helper method that is automatically