All posts by Jeremy

[WP7] Sound effect in a Silverlight Windows Phone 7 application

A coworker and I are currently working on a simple Silverlight game for the Windows Phone 7 platform. In order to give some feedback to our end-user, we decided to add sound effects. Here is a very short post about how we did that.

The first thing is to reference the Microsoft.Xna.Framework assembly in your project. This assembly is needed to access the low-level sound component of XNA right from your Silverlight application. You also need to have your sound effect in a WAVE format file.

Then we created a simple action (from the Blend Behavior toolkit) which is a TargetedTriggerAction:

public class SoundEffectAction : TargetedTriggerAction
{
    public string Source
    {
        get { return (string)GetValue(SourceProperty); }
        set { SetValue(SourceProperty, value); }
    }

    public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
        "Source", 
        typeof(string), 
        typeof(SoundEffectAction), 
        new PropertyMetadata(string.Empty));

    protected override void Invoke(object parameter)
    {
        if(!string.IsNullOrEmpty(this.Source)
        {
            var stream = TitleContainer.OpenStream(this.Source);
            if (stream != null)
            {
                var effect = SoundEffect.FromStream(stream);
                FrameworkDispatcher.Update();
                effect.Play();
            }
        }
    }
}

Using this action, we’re able to wire sound effect right in Blend which produces the following XAML code:


    
        
            
        
    
    

Simple, isn’t it ?

Attributes-based validation in a WPF MVVM application

Today, I’m proud to share with you my very first article available on CodeProject. This article presents a technique which can be used in order to add validation in a WPF MVVM application based on attribute. Basically, it means that you can write validation logic like that (notice the attribute associated to this property):

[Required(ErrorMessage = "Field 'FirstName' is required.")]
public string FirstName
{
    get
    {
        return this.firstName;
    }
    set
    {
        this.firstName = value;
        this.OnPropertyChanged("FirstName");
    }
}

Of course the article comes with a nice demo application:

You can read the full article here: Attributes-based validation in a WPF MVVM application


MVVM Frameworks Explorer updated

Today I’m releasing a new version of my MVVM Frameworks Explorer application. You can find the updated version here: http://www.japf.fr/silverlight/mvvm/index.html

Here is a list of the changes in this new version:

  • application updated to Silverlight 4
  • support is now detailed for WPF, Silverlight and Windows Phone
  • new frameworks added (MEFedMVVM…)
  • framework’s logo added
  • download count added (based on the information I found on CodePlex website)
  • about window

As always, feel free to give feedback 🙂