The Future of Web Content – HTML5, Flash & Mobile Apps
The recent introduction of the new Apple iPad has stirred the discussion over the future of web content and application runtime formats, and shone light onto the political and business battles emerging between Apple, Adobe and Google. These discussion are often highly polarized and irrational. My hope in this post is to help provide some balance and clarity onto this discussion. More here…
Does MVVM deserve the hype?
Ah, MVVM! MVVM is the rock star who packs the house at every XAML event. It’s in books, blog posts, and podcasts. You can’t swing a dead laptop without hitting someone who is spouting about the virtues of model-view-viewmodel. With so much hype, there’s bound to be backlash.
Does MVVM deserve the hype?
Short answer – no.
An Alternative?
You’ve got a complex UI with lots of rules, and you reject the MVVM best practice crap the whiteboarding architect is jamming down your throat. You’re gonna be … pragmatic!
A Silverlight Showcase – Top Albums
It is a Silverlight 3 app. You’re welcome to download the source (here) and do with it as you please. It uses the completely awesome Saluse Media Kit to create the playback visualization bars (in conjunction with the must have WriteableBitmapEx extensions for WriteableBitmap).
Communication Between Local Silverlight Applications using LocalMessageSender and LocalMessageReceiver
This makes it extremely easy to communicate between two different Silverlight applications. Granted, you could communicate between Silverlight instances before, but you had to use Javascript as a go-between. Now, it is much, much simpler, and as an added bonus, Silverlight apps can communicate from different browser pages! An app loaded in one browser tab can (with the right permissions) communicate to one on a different tab.
We have 2 examples here.
- The 1st example – A Silverlight app which has a table of employees. This Table View communicates back and forth with another Detail View Silverlight App. When you select an employee in the Table View, it populates the Detail View. In the Detail View, you can edit the employee and save it, or you can "add as new" which will communicates back to the Table View add a new employee to the table. This sample use a JSON Serializer (DataContractJsonSerializer) to serialize/deserialize the business object and use that as a payload for communication.
- The 2nd example is an old MFC Scribble like Silverlight Application. You can start each page in a different browser instance and draw in the sender and see your strokes duplicated in the receiver. The screen shot below was taken with the sender running in IE, and the receiver running in Firefox–two different browsers and two different processes.
The keys here are the LocalMessageReceiver and the LocalMessageSender. As you might guess, the receiver listens for messages, and the sender sends messages. If you want your Silverlight application to receive messages, you need to create a LocalMessageReceiver with some name, and tell the receiver to listen.
A collection of Behaviors and Actions for use in Expression Blend
Download from http://expressionblend.codeplex.com/
Some of the triggers, actions, behaviors, effects:
Note: CallDataMethod, InvokeDataCommand – a wonderful way to trigger a method/command in your Silverlight MVVM ViewModel
- PlayMedia- plays a media element
- PauseMedia- pauses a media element
- TogglePlayPauseMedia- toggles between play/pause on a media element
- StopMedia- stops a media element
- MouseGestureTrigger- triggers an action when the user makes a gesture on the element.
- MouseEventTrigger- allows more complex mouse triggers such as double-click or firing from handled events
- StateChangedTrigger- triggers when the state is changed
- CallDataMethod- An action which calls a method on the data context. Good for tying an event in your View to do something in the ViewModel for MVVM styled applications.
An example of calling the ViewModel’s ViewModel1_ComboBox_SelectionChanged method when a ComboBox item is selected:
// View.xaml
// Make sure the DataContext is set to an instance of the ViewModel1 somewhere in xaml
<ComboBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<si:CallDataMethod Method="ViewModel1_ComboBox_SelectionChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
...
// ViewModel1.cs
public void ViewModel1_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem item = e.AddedItems[0] as ComboBoxItem;
var text = item.Content.ToString();
}
- InvokeDataCommand- An action which invokes a command on the data context. Another behavior for MVVM integration.
Example of invoking the CheckOut command when a button is clicked:
<i:EventTrigger EventName="Click"> <si:InvokeDataCommand Command="{Binding ShoppingCart.CheckOutCommand}"/> </i:EventTrigger> - DataEventTrigger- triggers when an event is raised on the data context. Useful for doing something such as playing a sound or animation when something happens on the data context
- SetDataProperty- sets a property on the data context
- DataStateBehavior- switches between two states depending on the value of a binding
- FluidBindProperty- acts as a proxy for databound properties in order to animate the changing of the value
- PropertyChangedTrigger- triggers when the value of the property changes, regardless of the new value
- ClippingBehavior- Provides a rounded rectangular clipping that scales with the element. Useful since Silverlight and WPF clipping geometries don’t scale with objects
- GoToNextState- Go to the next state in a VisualStateManager. Useful for quickly navigating between various states
- GoToPreviousState- Go to the previous state in a VisualStateManager. Useful for quickly navigating between various states
- SetProperty- Similar to ChangePropertyAction but allows incrementing as well as setting
- ShowMessageBox- Displays a standard message box to the user
- ListBoxAddOne- Action which duplicates a random item in the ItemsSource collection of a ListBox. Useful for SketchFlow prototypes where you want to show adding a new item
- ListBoxRemoveOne- Action which removes a random item in the ItemsSource collection of a ListBox. Useful for SketchFlow prototypes to simulate removing an item.
- ListBoxRemoveThisItem- Action for use inside of a ListBoxItem which will remove the item from the data collection of the owning ListBox.
Download from http://expressionblend.codeplex.com/
Multiple-Constructor Injection using Unity IOC
Unity, and the dependency injection design pattern itself, really becomes useful is when the container generates instances of objects that have dependencies. It can automatically resolve the dependent object types required by the objects it creates, generate the appropriate concrete types, and then inject these concrete instances into the object it is creating.
The following shows a schematic view of the dependency injection process that Unity can accomplish.

The following are the types of injection together with descriptions of how they are applied using Unity:
- Constructor injection. This type of injection occurs automatically. When you create an instance of an object using the Unity container, it will automatically detect the constructor with the largest number of parameters and execute this, generating instances of each object defined in the constructor parameters. It resolves each parameter type through the container, applying any registrations or mappings for that type. If you want to specify a particular constructor for Unity to use, you can add the InjectionConstructor attribute to that constructor in the target class.
- Property (setter) injection. This type of injection is optional. You can add the Dependency attribute to any property declarations that you want Unity to resolve through the container. Unity will resolve that property type and set the value of the property to an instance of the resolved type.
- Method call injection. This type of injection is also optional. You can add the InjectionMethod attribute to any method declarations where you want Unity to resolve the method parameters through the container. Unity will resolve each parameter type and set the value of that parameter to an instance of the resolved type, and then it will execute the method. Method call injection is useful if you need to execute some type of initialization method within the target object.
Via http://msdn.microsoft.com/en-us/library/cc816062.aspx
Multiple-Constructor Injection Using an Attribute
When a target class contains more than one constructor with the same number of parameters, you must apply the InjectionConstructor attribute to the constructor that the Unity container will use to indicate which constructor the container should use. As with automatic constructor injection, you can specify the constructor parameters as a concrete type, or you can specify an interface or base class for which the Unity container contains a registered mapping.
e.g.
public class MyObject {
public MyObject(SomeOtherClass myObjA) { … }
[InjectionConstructor]
public MyObject(MyDependentClass myObjB) { … }
}
In your run-time code, use the Resolve method of the container to create an instance of the target class. The Unity container will instantiate the dependent concrete class defined in the attributed constructor and inject it into the target class. For example, the following code shows how you can instantiate the example target class named MyObject containing an attributed constructor that has a dependency on a class named MyDependentClass.
e.g.
IUnityContainer uContainer = new UnityContainer(); MyObject myInstance = uContainer.Resolve<MyObject>();
How Unity Resolves Target Constructors and Parameters
When a target class contains more than one constructor, Unity will use the one that has the InjectionConstructor attribute applied. If there is more than one constructor, and none carries the InjectionConstructor attribute, Unity will use the constructor with the most parameters. If there is more than one such constructor (more than one of the “longest” with the same number of parameters), Unity will raise an exception.
Constructor Injection with Existing Objects
If you use the RegisterInstance method to register an existing object, constructor injection does not take place on that object because it has already been created outside of the influence of the Unity container. Even if you call the BuildUp method of the container and pass it the existing object, constructor injection will never take place because the constructor will not execute. Instead, mark the constructor parameter containing the object you want to inject with the Dependency attribute to force property injection to take place on that object, and then call the BuildUp method. This is a similar process to property (setter) injection. It ensures that the dependent object can generate any dependent objects it requires. For more details, see Annotating Objects for Property (Setter) Injection.
A Silverlight 4 OOB Google Search Application
This application uses Google Search API and behaves like Internet Search Application with option to preview desired page in web browser (Silverlight 4) directly in this application.
Via http://bachelorthesis.zdechovan.com/silverlight-application-google-search/
3D in Silverlight Tutorial from Silverlight Buzz
- Controlling Projection in Silverlight 3
- Shadow effect using 3D projection in Silverlight 3
- Creating a 3D cube with images in Silverlight 3
- Using projection to build a 3D carousel in Silverlight 3
- Creating a 3d particle effect using just storyboards and behaviours
- Creating a 3d spiral animation using projection in Silverlight 3
Learn Blend in a Month (22 posts) from Silverlight Buzz
- What is Silverlight and Expression Blend
- Setting up your work space in Blend
- Importing artwork from other tools into Blend
- Drawing tools in Blend
- Using gradients in Blend
- Using Images and Video in Blend
- Using Blurs and Shadows in Blend
- Animating with Storyboards in Blend
- Adding easing and inertia to your animations in Blend
- Using the 3D tools to animate in Blend
- Using the Canvas element in Blend
- Using the Grid element in Blend
- Using the Stack Panel in Blend
- The differences between Text Box and Text Block in Blend
- Creating buttons and using States in Blend
- Changing the Mouse Icon graphic in Blend
- Out-the-box controls in Blend
- Using Behaviors to get things moving in Blend
- Using Resources to share styling in Blend
- Using Data Binding to share data in Blend
- Making an object re-usable as a User Control in Blend
- Legally using non-standard fonts in Silverlight and Blend


