Category Archives: Silverlight

Calculate EndpointAddress for Silverlight client

Because Silverlight checks the origin it considers http://localhost and http://127.0.0.1 as different locations. In case you want your visitors to be able to use both addresses you can recalculate the address as following: EndpointAddress GetEndpointAddress(EndpointAddress endpointAddress) { var scheme = … Continue reading

Posted in C#, Silverlight | Leave a comment

Creating graphs with the Silverlight Toolkit

As i wrote already: In a chart the elements on the X-axis are usually numbers or dates, and the elements on the Y-axis are usually doubles. We can define such a combination as following: public class Point<T> { public T … Continue reading

Posted in C#, Silverlight | Leave a comment

Silverlight and unit testing..

A while ago i was looking for a unittesting framework that can be used with Silverlight. Because i don’t want to launch a webbrowser on my buildserver i ruled the Unit Test Framework for Microsoft Silverlight out. A couple of … Continue reading

Posted in Silverlight | 1 Comment

Couple of methods missing on ObservableCollection

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 … Continue reading

Posted in C#, Silverlight, WPF | Leave a comment

Separation of concerns: Behavior = Trigger + TriggerAction

If you look at my KeyBehavior you notice that it is doing two things: register for events so that the behavior can be triggered and handle the actual command invocation. In order to enhance reuse we can refactor this KeyBehavior … Continue reading

Posted in C#, Silverlight | Leave a comment

True KeyBehavior with System.Windows.Interactivity.Behavior

Yesterday i demonstrated how attached properties can be used to invoke commands on specific key presses (and releases). With the aid of System.Windows.Interactivity.Behavior we can implement a true behavior and we get an extension point to do the required cleanup. … Continue reading

Posted in C#, Silverlight | 1 Comment

Silverlight: leveraging attached properties to handle key events

I strongly believe that input handling is a responsability that belongs to the View. At first i simply added the following in the code-behind of my GameView: protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.Key == Key.Left) Model.MovePlayerLeft(); … … Continue reading

Posted in C#, Silverlight | 1 Comment

Exploring graphical programming with Blend, Visual State Manager and Behaviors

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 … Continue reading

Posted in Silverlight, WPF | Leave a comment

ViewModel to translate domain messages to view events

Here is an example of a ViewModel that translates domain messages to view events: class GameViewModel : INotifyPropertyChanged, IListener<BoardChanged> { public event PropertyChangedEventHandler PropertyChanged = delegate { }; public GameViewModel() { var messageBus = ServiceLocator.MessageBus; messageBus.Subscribe<BoardChanged>(this); } void IListener<BoardChanged>.Handle(BoardChanged message) … Continue reading

Posted in C#, Silverlight, WPF | Leave a comment

About databinding and composite views

A couple of days ago i had a databound ItemsControl (collection of Model.Cell) which instantiated sub views (with their own viewmodel). <Grid.Resources> <DataTemplate x:Key="CellTemplate"> <views:CellView /> </DataTemplate> </Grid.Resources> <ItemsControl ItemTemplate="{StaticResource CellTemplate}" ItemsSource="{Binding Cells}" /> </Grid> Because each CellViewModel needs to … Continue reading

Posted in Patterns, Silverlight, WPF | Leave a comment