In WPF and Silverlight 4 there is something known as Commands on many controls. Since Silverlight 2, Commands has partially existed in the form of the definition of the interface for them; ICommand. Balder supports commands for some of its controls.
Commands are meant as a way of separating the UI from the logic in a cleaner way than a code-behind event for a page or usercontrol, they represent the behavior for a specific event and each control controls what event triggers a Command. For most controls in Balder this would be the MouseLeftButtonUp event if the mouse was over the object at the point of click.

Commands are what is often used in patterns such as MVVM (Model View ViewModel) and could be placed as properties on the ViewModel and databound directly on the Control. The reason for doing this seperation is for decoupling View from state and behavior.


public class ViewModel
   public ViewModel()
      SomeCommand = new MyCommand();
   public ICommand SomeCommand { get; private set; }

public class MyCommand : ICommand
   public event EventHandler CanExecuteChanged;

   public bool CanExecute(object parameter)
      return true;

   public void Execute(object parameter)

Hooking this up in your Xaml - page or UserControl

   <balder:Game Width="800" Height="600">
      <balder:Mesh AssetName="teapot.ase" Command="{Binding SomeCommand}"/>

When the Teapot is clicked, the SomeCommand will be fired if the CanExecute() method returns true.

Last edited Dec 2, 2009 at 7:19 PM by adept, version 1


No comments yet.