Mario
Mario

Reputation: 3455

Caliburn.Micro with label not binding by convention

I have been using Caliburn.Micro's binding via convention in Silverlight 5 and am loving it. Here is an example property from a ViewModel:

private String _vmStringProp = "";
public String VmStringProp
{
    get
    {
        return _vmStringProp;
    }

    set
    {
        _vmStringProp = value;
        NotifyOfPropertyChange(() => VmStringProp);
    }
}

This property is bound in the View just by naming:

<TextBox x:Name="VmStringProp" />

This works great. But if I change it to a TextBlock or Lable (example below) an exception is thrown.

<sdk:Label x:Name="VmStringProp" />

It works fine if you change it to bind like normal Silverlight but I would rather keep consistent throughout the project instead of having some bound via convention and others explicitly bound depending on what type of control. Does anyone know why I can't bind via convention with Labels and TextBlocks?

Upvotes: 2

Views: 1644

Answers (1)

nemesv
nemesv

Reputation: 139798

Caliburn.Micro comes with a set of default conventions for WPF/SL/WP7 but obviously not for every existing control, so the Silverlight sdk:Label is also missing.

You can find the built in conventions at the end of this article and a lots of info how conventions work.

Luckily it is very easy to add a new convetions just add the following code into your Bootstrapper's contructor:

public MyBootstrapper()
{
    ConventionManager
        .AddElementConvention<Label>(Label.ContentProperty, 
                                    "Content", 
                                    "DataContextChanged");  
}

Upvotes: 7

Related Questions