Our Devlicio.us Blogs

On February 28, 2010, Activision issued a Cease and Desist order against Phoenix Online Studios, creators of “The Silver Lining,” an unofficial sequel to the King's Quest series  The sequel had, in 2005, been approved for non-commercial release by the owner of the King’s Quest IP, Vivendi Universal.  The team has been working on the 5-part episodic King’s Quest Sequel for eight years (they started before 2005).  They had just completed their final milestone and were preparing to submit the game for approval to Vivendi Universal right before Activision and Vivendi merged. Immediately upon acquisition of the King’s Quest IP, Activision shut down Phoenix Studios, with no intent to uphold the previous agreements.

As a long time fan of adventure games, and someone who has always wanted a real sequel to KQ6, I am really saddened by this.  Personally, I plan not to have anything to do with Activision until they make this right.  I hope you will join me in this.  If you have a few minutes, please sign the online petition and consider sending a letter to Activision.  Resources are below.  Thank you.  Now, on with your regularly scheduled programming…

Online Petition:
http://www.petitionspot.com/petitions/savetsl/
Facebook Group:
http://www.facebook.com/group.php?gid=382202612795&ref=mf
MySpace Page:
http://www.myspace.com/savetsl
Form Letter for Contacting Activision:

http://www.tsl-game.com/forum/index.php?topic=8406.0

Comments [0]

The following code throws an exception. Can you spot the bug?

public class MyControl : Control
{
    public static DependencyProperty MyPropertyProperty = DependencyProperty.Register(
        "MyProperty",
        typeof (double),
        typeof (MyControl),
        new PropertyMetadata(0));

    public double MyProperty
    {
        get { return (double) GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }
}
Comments [0]

Silverlight 4 is now supporting the commanding that we’ve come to love from WPF. Commanding was a foundational feature for MVVM. It’s what enabled us to bind to methods on our view models.

John Papa has an excellent introductory post on using commands in Silverlight 4. This pattern is called the DelegatingCommand pattern (or sometimes RelayingCommand).

I’d like to show you the Caliburn way of handling this. I’m going to steal John’s viewmodel from the aforementioned post (and hope he doesn’t sue).

The viewmodel presents a collection of all products and a filtered collection of products. You can modify the filter by calling LoadProducts().

public class ProductViewModel
{
    public ProductViewModel()
    {
        Products = new ObservableCollection<Product>();

        AllProducts = new ObservableCollection<Product>
                          {
                              new Product {ProductId = 1, ProductName = "Apple"},
                              new Product {ProductId = 2, ProductName = "Orange"},
                              new Product {ProductId = 3, ProductName = "Banana"},
                              new Product {ProductId = 4, ProductName = "Pear"},
                              new Product {ProductId = 5, ProductName = "Grape"},
                              new Product {ProductId = 6, ProductName = "Grapefruit"},
                              new Product {ProductId = 7, ProductName = "Strawberry"},
                              new Product {ProductId = 8, ProductName = "Melon"},
                              new Product {ProductId = 9, ProductName = "Guava"},
                              new Product {ProductId = 10, ProductName = "Kiwi"},
                              new Product {ProductId = 11, ProductName = "Pineapple"},
                              new Product {ProductId = 12, ProductName = "Mango"}
                          };
    }

    public ObservableCollection<Product> AllProducts { get; set; }

    public ObservableCollection<Product> Products { get; set; }

    public void LoadProducts(string filter)
    {
        Products.Clear();
        var query = from p in AllProducts
                    where p.ProductName.ToLower().StartsWith(filter.ToLower())
                    select p;
        foreach (var item in query)
        {
            Products.Add(item);
        }
    }

    public bool CanLoadProducts
    {
        get { return true; }
    }
}

Let me point out a few notable differences between John’s original and my version of the viewmodel.

  • There is no ICommand property.
  • CanLoadProducts is a property on my model, it was a method on the original

The snippet from the corresponding view would look like this:

<StackPanel>
    <TextBox x:Name="filter" />
    <Button x:Name="LoadProducts" Content="Load" />
</StackPanel>

The Explanation

It’s binding by convention, and it is a new feature of Caliburn added after the 1.1 release[1]. So you’ll need to get the trunk to do this.

When you have a button named LoadProducts, Caliburn will look for a method on your viewmodel named LoadProducts and automagically handle the binding for you. In addition, it will check for either a method or property (as in this example) named CanLoadProducts that it will use to toggle the enable/disabled for the button. Also, since we have a parameter named “filter” on LoadProducts, Caliburn will check to see if there is an element in the view name “filter” and pull the value from that.

There’s a great deal more that you can do with conventions (and you can even plug in your own conventions).

This also works for Silverlight 3 and WPF.

You can also see an example of this in Ayende’s sample app Alexandria.

  1. Actually, you can do some of this in 1.0, but it is easier and much richer in the trunk. Ping the forums if you have a need to use it in 1.x.
Comments [3]

XAML Attributes on Separate Lines

Buried deep within the options for Visual Studio is a little switch that places your XAML attributes on separate lines. For example, instead of looking like this:

<TextBlock Text="Some Text" Margin="10 0" Grid.Column="1" />

Your XAML would look like this:

<TextBlock Text="Some Text"
           Margin="10 0"
           Grid.Column="1" />

But Christopher, why do I care?

I initially started using this option because it made code samples easier to read (especially when going to print). However, a more valuable reason is that this practice is source control friendly.

In particular, it makes understanding the delta in files much easier. Frequently, revising XAML means adjusting the values of the attributes, adding new attributes, and removing attributes. Keeping attributes on separate lines makes it much easier to both identify and isolate changes. (Which is very helpful when merging conflicts).

Enabling the Option

Here’s how to turn it on in both Visual Studio 2008 and 2010:

  • On the menu bar, Tools | Options
  • Navigate in the tree to Text Editor | XAML | Formatting |Spacing

 Visual Studio Options

Reformatting XAML

Visual Studio will attempt to respect this option after you’ve enabled. However, sometimes you’ll want to force some XAML to be reformatted explicitly.

On the menu bar, when you are editing XAML, select

Edit | Advanced | Format Document

The keyboard shortcut is Ctrl+K, Ctrl+D. (I really hope that’s the default shortcut).

Comments [7]

Alabama Code Camp in Mobile

I’ll be at the Alabama Code Camp this weekend in Mobile, AL, along our very own Alan Northam. Like all code camps, this is a free event. If you are anywhere in the area I recommend attending. The schedule is posted on the site and there are a lot of great sessions.

I’m doing two presentations: one on source control concepts that I did at the Jacksonville and Tallahassee code camps. The other is a brand new presentation about the basics of game development, with a primer for XNA and how to port the source to Silverlight using SilverSprite.

You can also follow the event on Twitter with the hashtag #ALCC.

Hope to see you there.

Comments [0]

View our blog archives, visit us at devlicio.us.