Skip to main content Skip to footer

XAML Binding Expressions for WPF

Never write another converter again with ComponentOne Binding Expressions for WPF.

  • Save time and write cleaner XAML with rich, inline expression syntax
  • Concatenate strings, compute formulas, and apply if/else logic directly in your binding statements without the need for code-behind converters
Download Free Trial

Why Choose Binding Expressions for WPF?

Increase Productivity

Save Time and Write Cleaner XAML

Save time and write cleaner XAML by taking advantage of rich, inline expression syntax.

Expression Functions

Evaluate Expressions in XAML

Perform simple expressions directly in XAML binding such as text concatenation and mathematical formulas.

No Dependencies

No Need for Converters

By using Binding Expressions, your XAML will be more expressive and 100% self-contained. You can reduce the number of converter classes in your code.

WPF Binding Expressions Key Features

Logical and Arithmetic Operators

Perform simple arithmetic and mathematical functions in your bindings. You can use any of the common logical (=, >, <, <>, >=, <=) and arithmetic (+, -, *, /, ^) operators. You can also group expressions using parentheses. For example, “Amount * 8.5%” returns the value of the Amount property times 0.085:

<TextBlock Text="{c1:C1Binding Expression='Amount * 8.5%'}" />
<TextBlock Text="{c1:C1Binding Expression='Amount * 8.5%', StringFormat='c'}" />
Formatting Values

Binding objects have a StringFormat property that you can use to control the format of bound values. For example, the following XAML snippet applies a currency format to the evaluated expression:

Conditional Formatting

You can apply conditional formatting to your bound values using the IF function, which performs conditional logic. For example, the following XAML snippet formats values greater than 1,000 to appear bold:

Text="{c1:C1Binding Amount}"
FontWeight="{c1:C1Binding Expression='IF(Amount &gt; 1000, |bold|, |normal|)' }" />
Text="{c1:C1Binding Expression=
'CONCATENATE(Amount, & quot; Tax: & quot;, Amount * 8.5%' }" />
Combining Values

You can use text functions to accomplish common scenarios like replacing characters, converting to upper or lower case, or combining multiple values into one. For example, you can use the CONCATENATE function to display the total amount in addition to the taxed amount with the following XAML snippet:

Use Quotes without Breaking Your XAML

Use quotes in your binding expressions without breaking your XAML. Binding Expressions for WPF support inline quotes in two forms: & quot; or use of the pipe (|) character. For example, the XAML snippet above could be rewritten with the following for more readability:

Text="{c1:C1Binding Expression='CONCATENATE(Amount, | Tax: |, Amount * 8.5%' }" />
Clean and Expressive XAML

By using Binding Expressions, your XAML will be much cleaner and more expressive — as well as 100% self-contained. You don't need any external converters referenced from elsewhere in your solution.

Parse and Evaluate Expressions

Binding objects use the CalcEngine class to parse and evaluate expressions. CalcEngine is a public class, and can be used independently to parse strings into Expression objects or to parse strings to evaluate resulting expressions. For example, you could have a calculated TextBox that allows users to type expressions, like 4 + 16, and have them evaluated when the control loses focus by using the CalcEngine’s Evaluate method.