Wednesday, November 18, 2009
#
Today we are happy to be able to announce the availability of some Silverlight 4 book content. For existing Silverlight developers looking to get up to speed quickly with the features we are releasing the Silverlight 4 Overview. This is a little over 50 pages of content covering the new Silverlight 4 features. For the rest of this week using code SL4DaveBlog at checkout you can get the new Silverlight 4 content for only $5 almost half off the normal price. More details on the book site http://www.silverlightjumpstart.com
For developers that are new to Silverlight but are comfortable with .NET we are releasing a preview of Silverlight 4 Jumpstart. Silverlight 4 Jumpstart content builds on the success of the Silverlight 3 Jumpstart book to offer content focused at the business .NET developer.
Both of these offerings are available today and will continue to evolve with the Silverlight 4 release. These are delivered in an electronic format (PDF) and will continue to be updated with more current releases of Silverlight 4.
The following is an excerpt from the Silverlight 4 Overview chapter that is available as part of Silverlight 4 Jumpstart Preview book or as a standalone chapter from SilverlightJumpstart.com. The full overview chapter covers all the major new features of Silverlight 4 to help you get up to speed quickly.
Microsoft has fast tracked Silverlight to be a strong competitor in the global RIA space and squarely positioned itself against competitors like Adobe, Google and Yahoo for production of the finest RIA toolset. The initial battleground was video, but we are now seeing Silverlight has strong potential for building business applications as well. We have tried through the previous chapters to streamline your learning of the current version of Silverlight by focusing on the key areas a business developer needs to know. Now it’s time to talk about the future and what the road ahead looks like for Silverlight.
It had only been about nine months since Silverlight 2 was released in October 2008 that Silverlight 3 hit the street in July 2009. Then, just four months after the release of Silverlight 3 Microsoft released Silverlight 4 Beta at its Professional Developer Conference in November 2009. Each of these releases build on the prior one to add new features while at the same time keeping compatibility to support this fast pace of innovation.
If I had to pick a single theme for the main items that are part of Silverlight 4 I would have to choose “You Asked, Microsoft built it”. I say that because many of the items like Printing or Web Camera/Microphone support for example were some of the highest user prioritized features. You can check that out for yourself at Silverlight.UserVoice.com and while you’re there add or vote on a couple of your requests.
Silverlight 4 is also a major deal because it’s the first release of Silverlight to support .NET 4 CLR (Common Language Runtime). This gives developers access to the latest runtime features that are added to CLR4 including things like dynamic object support.
In addition to the core Silverlight 4 Beta, Microsoft also released corresponding updates to the other tools and products used with Silverlight. The tools for working with Silverlight from within Visual Studio were updated to support the Silverlight 4 Beta. This includes increased designer support to make it easier to develop Silverlight applications without having to leave Visual Studio for a separate tool. A new version of the Silverlight Toolkit was also released that goes along with the Silverlight 4 update. An update was also released for .NET RIA Services which has now been renamed as WCF RIA Services to reflect the fact that it now rides on top of WCF. This is an evolution of the prior .NET RIA Services releases and positions it to leverage WCF as a foundation to build on going forward. In addition to the WCF change a number of additional features such as improved inheritance support were added to WCF RIA Services in this release. Finally, a preview release of Blend for .NET 4 was released to allow it to work with Silverlight 4.
In the rest of this chapter we are going to preview some of these features that you will see in the Silverlight 4 Beta release.
Web Camera / Microphone Support
Silverlight 4 now allows developers to access to the raw audio and video streams on the local machine from applications running both in and out of the browser. Using these capabilities developers can write applications including capture and collaboration using audio and video. This is built-in to the core runtime and no other special downloads are required on each machine. When the audio or video is accessed for the first time by the application the user will be prompted to approve the request. This ensures that audio and video is never accessed without the user’s knowledge preventing applications that capture silently in the background. The following is an example of the prompt the user sees when the application requests access to the devices.
You will notice in the above image the site name is displayed. This is another safeguard to ensure the user knows which site is requesting access to the devices. Access is granted to just this application and only for this session of the application. Currently there is no option to persist the user’s approval to avoid re-prompting each time the application is run. Additionally, it’s all or nothing; you don’t get to choose video or microphone. It’s a combined approval.
Users with multiple devices can select the devices they want to be the default devices using the properties on the Silverlight plug-in. This can be selected by right-clicking on a Silverlight application and going to the Webcam/Mic tab.
The following is an example of what you will see on that tab.
Developers can get access to the chosen devices using the CaptureDeviceConfiguration class. Using this class you can call the GetDefaultAudioCaptureDevice or GetDefaultVideoCaptureDevice methods to retrieve the users selected defaults. The class also has GetAvailableAudioCaptureDevices and GetAvailableVideoCaptureDevices methods that allow you to enumerate the available devices if you want more control of choosing a device besides the default.
Prior to using the devices you must request access to the device by calling the RequestDeviceAccess() method from the CaptureDeviceConfiguration class. When this method is called it is responsible for showing the user approval dialog we saw earlier. This method must be called from a user initiated event handler like the event handler for a button click event. If you call it at other times it will either not do anything or produce an error. Using the AllowedDeviceAccess property you can query if access has already been granted to the device.
The quickest way to get started using the video is to attach the capture from the device to a VideoBrush and then use the brush to paint the background of a border. The following XAML sets up the button to trigger the capture and a border that we will paint with a video brush.
| <StackPanel> <Button x:Name="btnStartvideo" Click="btnStartvideo_Click" Content="Start Video"></Button> <Border x:Name="borderVideo" Height="200" Width="200"></Border> </StackPanel> |
Next, the following private method TurnOnVideo method is called from the handler for the click event on the button. This satisfies the requirement to be user initiated.
| private void TurnOnVideo() { VideoCaptureDevice videoCap = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); AudioCaptureDevice audioCap = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice(); CaptureSource capsource = new CaptureSource(); capsource.AudioCaptureDevice = audioCap; capsource.VideoCaptureDevice = videoCap; if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { capsource.Start(); VideoBrush vidBrush = new VideoBrush(); vidBrush.SetSource(capsource); borderVideo.Background = vidBrush; } } |
As you can see in the code above, default audio and video devices are retrieved and assigned to a CaptureSource. Access to the devices is then checked and requested if not already approved.
If access is granted the Start() method on the CaptureSource is invoked to begin capturing audio and video. Finally, the VideoBrush source is set to the CaptureSource instance and the background on the border is set to the VideoBrush.
Overtime we will probably see some very interesting applications of the audio and video support. One example that we put together was using it with Microsoft Dynamics CRM. In this example application a membership application was simulated that associated members with pictures and stored the pictures in a database. Think of a place similar to Costco, Sam’s Club or your local gym that snaps your photo for their records.
In the following image you can see how a tab has been added to the Contact form using the CRM customization capabilities.
A Silverlight 4 application is then hosted inside that tab that will provide the user experience for capturing the images. When the Start Camera button is clicked the user will be prompted to approve the access and the video feed will begin as you can see below.
The video feed will keep showing the live image updated from the web cam until stopped. The Capture button on the above application allows the user to capture one of the image frames from the capture source. The AsyncCaptureImage(..) method on the CaptureSource class allows you to request that a frame be captured and your callback invoked. The callback is then invoked and passed a WriteableBitmap representing the captured frame.
This image can then be saved back to the Dynamics CRM server and associated with the record being viewed.
In the above example we looked at how you could use the video capabilities to capture a static image. More advanced applications are also possible for things like collaboration by showing the real time audio and video feed of multiple users.
You have been reading about one of the many new and exciting features of Silverlight 4 that are covered in the complete overview chapter. Visit SilverlightJumpstart.com today to access the full chapter.
Tuesday, August 11, 2009
#
The DataForm like the DataGrid control by default has the ability to auto generate fields based on the public properties of the object bound it. This is controlled by the AutoGenerateFields property which is set to true by default. I think the most common use for this feature is building demo apps and prototyping. In those types of uses you can usually overlook the fact that there are a few properties with fields generated that you would never show a user of a business application. In the rest of this blog post I will walk you through how you can add more control using a Silverlight 3 Behavior.
You can now also have more control over field generation by adding attributes to the class that you are binding to using the Editable and Display attributes. Editable allows you to mark the property to be treated as read only or generate a one way binding. Display as used below sets the AutoGenerateField property to false to ensure that the Age property doesn’t generate a UI Element.
You might have done similar things during the Silverlight 3 beta using the Bindable attribute which was replaced by using Display and Editable – see the change doc for more details.
If you are using .NET RIA Services it helps by projecting attributes you place on the server side class metadata to the Silverlight client code generated. When binding a class projected to the client by RIA services no extra work is required because these attributes are there.
These attributes help a lot and make it so there are even more places where the DataForm can be used. One of the problems though is there are times where either you don’t want to mess with meta data, don’t have control over the class to add meta data, want a different set of fields included or excluded for a particular use. In any of those cases probably the most common suggested work around is setting the AutoGenerateFields to false and specify a specific list of fields. That can get real tedious real quick especially if you just wanted to hide a couple of fields.
The DataForm provides a useful event to help out here it’s called AutoGeneratingField. This event is called as the DataForm is about to generate a field for a property. In the event arguments you are passed the property name, the property type, a Field property and finally a Cancel flag. The Field property is used if you want to provide a DataField back based on your own evaluation of the property name or type. The Cancel flag though is what were most interested in for this blog post because it allows you to cancel generation of a field. Using an event handler on that event you could accomplish the same thing we did with the attribute above as you can see in the following example.
While that’s helpful, I was really hoping for a way to package it up to be a little more reusable. One way you could do that is inherit your own MyDataForm class from DataForm and override the OnAutoGenerateField method as you can see in the following example.
I’ve of course over simplified this a little but you get the point. I basically have a property that can pass in the fields I want and if not in the list I cancel the generation. I would probably also include an ExcludeFields property as well so you could stop one or two fields from generating. Both can be useful in making the DataForm useful for more scenarios. The problem with this approach is that you then have to always use the MyDataForm class to get the benefit. In the next example we will look at how to use a Silverlight Behavior.
Behaviors and Triggers are a new feature that we gained with Silverlight 3 and are packaged as part of the blend SDK in the System.Windows.Interactivity assembly. They are nice because they let you add capabilities to existing controls without having to inherit from the control. In the rest of this post we are going to build a behavior to allow us to filter the fields. The first thing that needs to be done after we add a reference to the System.Windows.interactivity assembly is to create our class that inherits from Behavior as you see below.
You will notice that we specify DataForm as the control type for the behavior – this allows us to have a typed property AssociatedObject that is of type DataForm.
What we want to do is hook into the AutoFieldGeneratingEvent like we did in the past examples. Behaviors provide an OnAttached method that you can override and accomplish registering the event handler as you can see below.
In the event handler we basically use similar logic like we did in the prior example or more fancy if we want but the idea is for fields we want to not show we set the Cancel flag.
Using the behavior is pretty easy the first thing you need to do is declare a namespace reference for the System.Windows.Interactivity and the library that contains the behavior class as you can see below.
Then on the DataForm control instance we can hook up our behavior by using the Interaction.Behaviors markup as you can see below.
Behaviors are cool because they can easily attach on to an existing control to add behavior that makes sense. By attaching on they keep the core control from becoming bloated with features that only get used once and a while.
If you think this might be useful to you, drop me an e-mail and I will shoot you over a copy of the code.
Saturday, August 08, 2009
#
One thing for sure there hasn’t been a dull moment in technology for a while. The ever increasing pace of change can make it almost as challenging as picking stocks to know which technology to choose.
HTML is one of the interesting technologies because it has been the foundation of the web evolution. Without going back on a history trip, lets just agree its been around for a while. Last updated with the HTML 4.01 specification back in 1999, and with a new HTML 5 specification in the works.
Recently, there’s been a lot of hype around HTML 5. In fact almost enough you might think it’s ready to go and fully supported. But as Philippe Le Hegaret simply stated on the W3C blog “HTML 5 isn’t a standard yet” The first draft of HTML 5 can be traced back over a year to January 2008. The most recent draft was just recently published. One challenge with HTML 5 is not all the players have been at the table. In fact Microsoft has just recently joined in, up till now it’s been a Google/ Apple show.
What’s the rush for HTML 5? Simple, HTML hasn’t kept pace with other emerging RIA technologies like Flash and Silverlight. HTML 5 promises a lot of fancy new features like built in video, audio, and local data storage to name a few that will close the gap. This has lead some to speculate if HTML 5 could be the death to Flash, Silverlight and other RIA technologies. I wouldn’t call your florist and order flowers for the funerals just yet….
Why you ask? HTML 5 is in a fight with some very nimble competing technologies. The RIA space has been fire with new features being released at neck breaking speed. Most RIA technologies like Flash and Silverlight have streamlined their release cycles to 9 months or less because they don’t have to battle it out with a standards committee. Most of the competing technologies simply depend on the object tag in HTML to host their plug-in and then they manage the plug-in area as they see fit. That means that Adobe only has to agree with them self for Flash changes, and same for Microsoft with Silverlight. HTML 5 has two big challenges. First, getting all the players to approve the new specification. Second, and probably an even more challenging aspect is to get it implemented in a consistent way in enough users browsers. Even today, with the push towards standards in IE8 most the time unless you have a real simple page it won’t look the same the first time you run it in the different browsers. In fact, sometimes they look radically different!
Like movie sequels you can’t help but think are we just trying to make HTML like all the other popular movies instead of letting it do what it was designed to do originally. By trying to morph it to be closer to RIA technologies do we risk causing even more fragmentation? I know for me, writing an application that just works in different browsers and even out of the browser is compelling. Anytime I spend time working on resolving a browser compatibility issue I feel it’s 100% wasted time that I could have spent building something with higher business value. Am I against standards? No, I think they have their place, however, the more complex they get the harder it is to get consensus and compliance.
So what do you think about HTML 5? Should we start a pool of when it will finally be approved?
Wednesday, July 29, 2009
#
One of the more useful services that comes out of the box with .NET RIA Services is an authentication service. In fact, if you create an application using the Silverlight Business Application template it comes already wired up for use with the ASP.NET authentication system. Brad Abrams has a good walkthrough of the basics of using this service here.
As configured when you create your new application using this template the login is not retained from one browser session to the next. We are in the process of building a training center application and a frequent request from users is to not have to log in each time. They would like to be able to click “Keep me logged in” and have it be retained for a period of time. In the rest of this blog post I’m going to walk through one of the ways to enable this using the .NET RIA Services authentication service.
The first step is to modify the LoginWindow to have a check box to allow the user to indicate they want to stay logged in as you can see in the following image.
This requires a simple addition to the XAML for the LoginWindow as you can see below.
<StackPanel Style="{StaticResource LoginControlStyle}">
<TextBlock Text="" Style="{StaticResource LoginTextStyle}"/>
<CheckBox x:Name="checkStayLoggedIn" Content="Stay logged in 2 weeks"></CheckBox>
</StackPanel>
We chose two weeks because of the type of application you can make this as long or as short as you would like. Really what we are going to use this for is to decide if we check the persisted property on the Login call. Previously, our login call looked like the following just passing the user and password.
_authOp = _authService.Login(this.loginUserNameBox.Text, this.loginPasswordBox.Password);
We are going to change this logic to to set the IsPersited property on the LoginParameters as you can see in the following revised code.
LoginParameters loginParms = new LoginParameters(this.loginUserNameBox.Text,
this.loginPasswordBox.Password, checkStayLoggedIn.IsChecked.Value, string.Empty);
_authOp = _authService.Login(loginParms);
Now because we said we are going to keep them logged in for 2 weeks, we also need to make a small change server side to the authentication section in the web.config. Here we are going to add a Forms timeout with a value in minutes.
<authentication mode="Forms">
<forms timeout="20160"/>
</authentication>
So at this point that all works, however, when we revisit the application it doesn’t know we are already logged in. In order to know that, we need to add a call to the LoadUser method. In this particular application in the MainPage loaded event handler we are showing the LoginWindow by default to allow the user to login. Our revised code now calls the LoadUser async method from the loaded event handler as you can see below.
AuthenticationService _authService = RiaContext.Current.Authentication;
var loadUserOp = _authService.LoadUser();
loadUserOp.Completed += new EventHandler(loadUserOp_Completed);
Finally, when this completes it calls the loadUserOp_Completed event handler and we can check to see if the user is logged in and if not show the LoginWindow
void loadUserOp_Completed(object sender, EventArgs e)
{
if (!RiaContext.Current.User.IsAuthenticated)
new LoginWindow().Show();
}
In the case where the user had persisted the login the IsAuthenticated is now set to true and we don’t show the LoginWindow.
Wednesday, July 01, 2009
#
It’s only been about 9 months since Silverlight 2 was released in October 2008, we are nearing the release of Silverlight 3, and already the momentum is building for Silverlight 4. A thread recently has been started on the Silverlight forum to capture people’s wish list. You can read the full forum thread here and add on your own wishes.
I’m preparing to finish writing part of a chapter that talks about “The Road Ahead” for our soon to be released Silverlight 3 book so I had some help pulling together a summary of what people are asking for already as of today. The following is just a snapshot but thought you might find it interesting if you didn’t have time to read the long forum list – The top 10 or so on the list all had multiple people requesting those items.
| Printing support |
| Right-click context menus |
| Host HTML content |
| Better shaders |
| Better mouse support |
| Fix WriteableBitmap |
| Mic support |
| Better LocalMessage APIs |
| Better File IO Support |
| Full 3D w/GPU acceleration |
| WebCam support |
| Concurrent release on Linux |
| Audio streaming |
| Chrome in OOB applications |
| Deep linking/Navigation in OOB apps |
| Reconsider OOB model |
| Export UI as bitmap |
| Complete source code for controls |
| Better Unit Testing |
| Text right to left |
| Mobile support |
| Better tables (merge columns and such) |
| Copy text from a textblock |
| Make TCP/IP compatible w/Flash |
| SQL reports |
| Expose PixelShader.SetStreamSource() |
| Improve rendering performance |
| Tweening/morphing support |
| Intellisense in XAML for Blend |
| Animated images |
| Pop-up Silverlight windows |
| Faster Silverlight windowless mode |
| Silverlight as ActiveX control |
| Better compression |
| Custom Open/Save file dialogs |
| Complete DX10 support |
| Silverlight apps directly installed OOB |
Sunday, June 28, 2009
#
From The Silverlight Blog: http://team.silverlight.net/announcements/silverlight-ads-on-xbox-live-announced-at-cannes/
Microsoft announced it will bring Interactive Advertising Bureau (IAB) recognized rich media technologies including Silverlight to Xbox LIVE within the next year
From Pete Brown’s Blog: http://tinyurl.com/ljede5
Pete Brown demonstrates how to bind to a UI element, with the example being a character count for a textbox.
From Laurent Bugnion’s Blog: http://geekswithblogs.net/lbugnion/archive/2009/06/16/mvvm-light-toolkit-silverlight-edition-posted.aspx
Laurent Bugnion has put together a toolkit that allows for easier MVVM development in WPF and Silverlight applications.
From Ian Blackburn’s Blog: http://silverlightforbusiness.net/2009/06/23/pushing-data-from-the-server-to-silverlight-3-using-a-duplex-wcf-service/
Ian Blackburn discussed how Silverlight 3 can be used to push data from the server with a Duplex WCF service.
From Nigel Sampson’s Blog: http://compiledexperience.com/Blog/post/Silverlight-3-Behaviors-Double-Click-Trigger.aspx
Nigel shows how to use a Double Click Trigger, as a Silverlight or WCF behavior, within Microsoft Expression Blend.
From Mike Taulty’s Blog: http://tinyurl.com/lx6pq8
Wintellect has published a whitepaper outlining the differences between WPF and Silverlight
From The Silverlight Blog: http://team.silverlight.net/announcements/what-is-expression/
The Silverlight team discusses what Expression actually is and gives a useful history on the conception of each of the products within.
From Tim Heuer’s Blog: http://timheuer.com/blog/archive/2009/06/05/verify-your-silverlight-application-compatibility.aspx
Tim shows the techniques for keeping your Silverlight 2 applications compatible with Silverlight 3 with the upcoming release.
From David Yack’s Blog:
http://blog.davidyack.com/journal/2009/6/28/ria-services-domain-data-source-invalid-property-errors.html
David talks about how to track down invalid property errors when using .NET RIA Services DomainDataSource controls.
Wednesday, April 15, 2009
#
For years there has been debate between applications deployed to the desktop and applications accessed via the web browser. Like political opponents the debate has been fierce and each side evolving over the years. Deployment complexity and richness of the user interface have always been two of the central battles fought. Each technology has made dramatic improvement including things like Click Once to ease deployment of Smart Client's to AJAX to make web applications more responsive and user friendly. Ongoing investments by Microsoft in WPF and ASP.NET AJAX 4 make clear that neither of these concepts will go away in the foreseeable future.
Silverlight however brings to the table a number of unifying concepts that both web and desktop developers should find appealing. Early on, Silverlight was thought by many to be simply a glorified Adobe Flash competitor offering a way to build a video player with the Microsoft tools. The reality, while it may well be a competitor in that space, its potential for being able to build rich business applications is really where it starts to get interesting. Additionally, as you consider the number of .NET capable developers already trained to build applications using similar Microsoft .NET related technologies it becomes clearer how Silverlight traction will begin to outpace competitors in the space at an amazing rate.
The time has arrived for anyone involved in business application architecture and related technology decisions to begin to engage in understanding the changing landscape. This would include not only ISVs, but also corporate developers building internal line of business applications. That's not saying everyone should move today to Silverlight, but should invest in understanding what changes are emerging. By making the investment in learning, you will be well positioned as the application user interface space continues to evolve over the next couple of years.
The introduction of Silverlight 3 beta makes real the commitment toward Silverlight being more than just a media player. Silverlight 3 introduces more business focused controls, more data and business logic connectivity as well as what could turn out to be the real “Click Once" deployment experience.
Silverlight 3 along with Microsoft .NET RIA Services extend the core connectivity plumbing to offer a richer way of extending business data and logic to the client application. As we will discuss in the future these services make it possible to share business logic as appropriate with the Silverlight client while keeping centralized business rules. This goes directly toward addressing and reducing complexity and developer productivity issues of these types of applications.
Traditionally, plug-ins like flash and Silverlight run in a web browser. As the lines between a true desktop application and a web application blur, so does the ability of Silverlight to run outside the browser. Live Mesh offered the first glimpse when it was announced at Microsoft PDC in October 2008 of a Silverlight application out of the browser with Mesh. Silverlight 3 continues that capability allowing a user to choose to install a Silverlight application to their start menu or desktop for easy access. When launched after saving the Silverlight application runs in a standalone process outside the browser window. Unlike competing technologies, this out of browser experience still allows the developer to use the same code and binaries both in and out of the browser. Using local storage resources and Silverlight's support to detect network availability these out of browser applications can also still run offline disconnected from the network. For many, this will be the unifying capability to further bring together desktop and web application development.
It's easy to jump to conclusions that ASP.NET is dead, or WPF is dead and it's important to understand how Silverlight fits in. The reality is, that all three technologies offer unique value propositions for developers building applications. While nobody has a crystal ball to predict the future we can look at how that plays out today. Today, ASP.NET offers applications the broadest deployment across a diverse set of clients. For broad consumer focused applications ASP.NET will continue to be the most viable option. Silverlight will start to be introduced more often in these applications as rich islands offering users specialized functionality. Developers will continue to build WPF applications to take advantage of having full access to desktop devices and the ability to have other desktop specific features. In some cases we will see lite versions of applications built on Silverlight, with full or more desktop feature enabled versions offered in WPF. In fact, frameworks and strategies are starting to emerge to improve the ability to build an application targeted for both Silverlight and WPF.
Join us as we continue to discuss and connect all these concepts into a clearer picture of how you build business applications using Silverlight. We will start with the basics of when to use Silverlight, move on to architecture concepts, and then steadily discuss the core building blocks that are required to put together a business application.
Today, we launched this blog, a new Twitter account and soon a new website that will be supporting a Silverlight 3 book focused on building business applications with Silverlight. Soon we will be releasing more details about the book and how you can get early access. If you would like to get notified sign up for the book notification list here.