0
votes

Is there a way to bind a Silverlight control to an object (or database table's row) which contains the values of several control's properties, doing so without by define the binding for each property?

For instance: Let's say I have the class (or entity based on database table's row) with the following values:

class TextBlockValues
{
    public string Text{get; set;}
    public string HorizontalAlignment{get; set;}
    public string VerticalAlignment{get; set;}
}

I want to bind it to a TextBlock in my silverlight application (again without explicit specify the binding for each property).

Thank you for your time.

2
Do you want something more along the lines of automatically binding each and every property in TextBlockValues to any compatible item with a single line of code?sukru
Yes. Although I'm able to write code doing so, I want to know if there is silverlight out-of-the-box functionality.roishabtai

2 Answers

0
votes

There are two parts in a binding: DataContext and the actual Binding objects. Once you set up the data context for an item, all the properties, and children will automatically use that.

For example:

<TextBlock Name="CaptionText" Text="{Binding Text}" HorizontalAlignment="{Binding HorizontalAlignment}" Height="20" TextAlignment="Center" FontStretch="Expanded" FontSize="13" />

And in the .cs file:

CaptionText.DataContext = myObject;
0
votes

If I understand your question right the answer is no. Even though you can set the control's DataContext you still have to bind which property in the control binds to what in the class.