Introduction to Binding Expressions > The C1Binding Class |
The C1Binding class addresses these issues by allowing you to use rich expressions in your bindings. Using C1Binding, the example above could be written as:
XAML |
Copy Code
|
---|---|
<TextBlock Text="{c1:C1BindingExpression='concatenate(FirstName, | |, LastName)' }" Foreground="{c1:C1BindingExpression='if(Amount < 0, |red|, |black|)' }" /> |
Notice how much simpler and more direct this version is. There are no resources and no converters. The meaning of the bindings is clear from the XAML.
If the XAML author decided that the full name should be displayed as "Last, First" instead, he could make the change directly in the XAML. If he wanted negative amounts to be shown in bold, that would be easy too:
XAML |
Copy Code
|
---|---|
<TextBlock Text="{c1:C1BindingExpression='concatenate(FirstName, | |, LastName)' }" Foreground="{c1:C1BindingExpression='if(Amount < 0, |red|, |black|)' }" /> FontWeight="{c1:C1BindingExpression='if(Amount < 0, |bold|, |normal|)' }" /> |
In the expressions above, the vertical bars represent quotes. They could also be written as ", but the vertical bars are easier to type and read.
The "Expression=" term in the expressions above is optional in WPF. It is required in Silverlight 5, currently in beta. It may not be required by the time Silverlight 5 ships.