Search code examples
c#custom-controlsexpression-blend

Databinding to a custom control in Expression Blend


I created a custom controll in expression Blend and added a property. I found the property in Blend, but the option for create a databinding isn't available. What do I have to make that I can add databindings through Blend?

Code Property:

    public string TileText
    {
        get { return this.labelTileText.Text; }
        set { this.labelTileText.Text = value; }
    }

Solution

  • If you want to enable databinding on a property of a custom control, you need to create a dependency property for that property.

    The property:

    public string TileText { 
         get { return this.labelTileText.Text; } 
         set { this.labelTileText.Text = value; } 
    }
    

    Dependency property:

    public static readonly DependencyProperty TileTextProperty = DependencyProperty.Register(
    "TileText", typeof(String), typeof(ClassName), new UIPropertyMetadata("default value", callBack));
    

    And then you should implement that callBack function that to be called whenever 'TileText' property is changed.