Posted by timvw on November 6, 2009
Here are a couple of methods that are missing on ObservableCollection<T>:
public static class ObservableCollectionExtensions
public static void AddRange<t>(this ObservableCollection<t> observableCollection, IEnumerable<t> elements)
foreach (var element in elements) observableCollection.Add(element);
public static ObservableCollection<t> Create<t>(IEnumerable<t> elements)
var observableCollection = new ObservableCollection<t>();
Posted by timvw on October 16, 2009
A while ago i presented the ControlStateMachine and in Silverlight this concept is implemented as the Visual State Manager.
In my sokoban implementation i have a cellview which exists out of 6 canvasses but only two of them (one for the cell type and one for the piece type) are visible at any given point in time. I have implemented this with 6 properties CanvasXVisible (with X being Player, Box, Wall, Goal, Floor and Cell) in my ViewModel but a State Machine / Manager may help clarify how the visibility of the canvasses are related. Here are the 2 visual state groups and their states that i would need for the CellView:
As you can see there is quite a lof of XAML involved to make the correct canvas visible:
<objectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"
For a simple modification to the Visibility property this seems like overkill but in many situations you will want to change more than this one property.
With the aid of the behaviors that come with Blend i can quickly add a couple of radio buttons, toss in some gotostate actions and end up with an interactive application:
Feel free to try it yourself by changing the radio buttons:
Conclusion: All in all it is relatively easy to create interactive applications using Blend without writing a single line of code. Too bad that the behaviors are in an Expression assembly and don’t come with standard Silverlight. Another attention point is the maintainability of this new style of programming.