ComponentOne Binding Expressions for WPF and Silverlight
Introduction to Binding Expressions / The C1Binding Class / C1Binding Usage Scenarios
In This Topic
    C1Binding Usage Scenarios
    In This Topic

    Simple Arithmetic:
    Suppose you want to display taxes due on a certain amount. Using traditional bindings, you would need a converter to calculate the tax amount. Using C1Binding, you can calculate the amount using a simple expression:

    XAML
    Copy Code
    <TextBlock
       Text="{c1:C1BindingExpression='Amount * 8.5%' }"
    


     

    Combining Values:
    Suppose you want to extend the scenario above and display the total amount in addition to the tax amount. You could do that using several TextBlock elements, but it would be more efficient to use a single TextBlock and a C1Binding based on the CONCATENATE function:

    XAML
    Copy Code
    <TextBlock
       Text="{c1:C1BindingExpression=
         'CONCATENATE(Amount, | Tax: |, Amount * 8.5%' }"
    


     

    Formatting Values:
    C1Binding
    and regular Binding objects have a StringFormat property that you can use to control the format of bound values. If your binding expression requires formatting several parts of the output, you can use the TEXT function as follows:

    XAML
    Copy Code
    <TextBlock
       Text="{c1:C1BindingExpression=
         'CONCATENATE(TEXT(Amount, |c|), | Tax: |, TEXT(Amount * 8.5%, |c|))' }"
    


     

    Conditional Formatting:
    Suppose you want to create a user interface where amounts greater than a certain value are displayed in bold and red. You can accomplish this using the IF function, which performs conditional logic:

    XAML
    Copy Code
    <TextBlock
       Text="{c1:C1BindingExpression='Amount', StringFormat='c'}"
       Foreground="{c1:C1BindingExpression='if(Amount &gt; 1000, |red|, |black|)' }" />
       FontWeight="{c1:C1BindingExpression='if(Amount &gt; 1000, |bold|, |normal|)' }" />