Back to Devexpress

Language Specification

wpf-115777-mvvm-framework-dxbinding-language-specification.md

latest6.7 KB
Original Source

Language Specification

  • Aug 25, 2023
  • 6 minutes to read

DevExpress binding mechanism uses its own language. This language combines C# and XAML rules. This topic describes these rules in detail.

Literals

The following literals are used in the same way as those in C#.

xaml
<TextBlock Text="{DXBinding 4}"/>
<TextBlock Text="{DXBinding '4'}"/>
<TextBlock Text="{DXBinding Expr='4'}"/>

<TextBlock Text="{DXBinding 4UL}"/>
<TextBlock Text="{DXBinding .4}"/>
<TextBlock Text="{DXBinding 0.4}"/>
<TextBlock Text="{DXBinding 4d}"/>
<TextBlock Text="{DXBinding 4e1}"/>
<TextBlock Text="{DXBinding 4e+1}"/>
<TextBlock Text="{DXBinding 4e-1}"/>

To define a string literal, use the ` (grave accent) symbol.

xaml
<TextBlock Text="{DXBinding `a string`}"/>
<TextBlock Text="{DXBinding Expr='`a string`'}"/>

The ‘ true ‘, ‘ false ‘, ‘ null ‘ words are reserved. Words ‘ True ‘, ‘ False ‘, ‘ Null ‘ are not literals.

xaml
<TextBlock Text="{DXBinding true}"/>
<TextBlock Text="{DXBinding false}"/>
<TextBlock Text="{DXBinding null}"/>
<TextBlock Text="{DXBinding True}"/> <!-- wrong (True is considered as a property) -->
<TextBlock Text="{DXBinding False}"/> <!-- wrong (False is considered as a property) -->
<TextBlock Text="{DXBinding Null}"/> <!-- wrong (Null is considered as a property) -->

Char constants are defined as follows:

xaml
<TextBlock Text="{DXBinding Expr='`a`[0]'}"/>

Properties

The following properties are used in the same way as those in C#.

xaml
<!--DevExpress DXBinding--> 
<TextBlock Text="{DXBinding 'Customer.FirstName + ` ` + Customer.LastName'}"/>
<!--Standard approach-->
<TextBlock>
    <TextBlock.Text>
        <MultiBinding Converter="{local:Converter}">
            <Binding Path="Customer.FirstName"/>
            <Binding Path="Customer.LastName"/>
        </MultiBinding>
    </TextBlock.Text>
</TextBlock>

Functions

You can invoke functions inside the DXBinding ‘s expression and pass parameters to them.

xaml
<TextBlock Text="{DXBinding 'Calculate()'}"/>
<TextBlock Text="{DXBinding 'Calculate(PropA, PropB.Prop1 + 2).PropC'}"/>
<Button Command="{DXCommand 'Calculate(PropA, PropB.Prop1 + 2)'}"/>
<UserControl Loaded="{DXEvent 'Calculate(PropA, PropB.Prop1 + 2)'}"/>

Indexer

The indexer is used in the same way as the one in C#.

xaml
<TextBlock Text="{DXBinding '[1]'}"/>
<TextBlock Text="{DXBinding 'Property[1+1]'}"/>

The DXBinding extension does not support notifications for indexer properties.

Types and Static Properties

Type definitions start with the $ symbol.

There are some primitive types: $int , $double , …, $string , $object , $bool.

The XAML engine resolves the other types.

xaml
<TextBlock Text="{DXBinding '$int.MaxValue'}"/>
<TextBlock Text="{DXBinding '$Window.CurrentWindow'}"/>
<TextBlock Text="{DXBinding '$dx:DXWindow.CurrentWindow'}"/>
<!-- Using enums -->
<TextBlock Text="Text" Visibility="{DXBinding $Visibility.Hidden}"/>

The typeof word is reserved.

xaml
<TextBlock Text="{DXBinding 'typeof($int)'}"/>
<TextBlock Text="{DXBinding 'typeof($Window)'}"/>
<TextBlock Text="{DXBinding 'typeof($dx:DXWindow)'}"/>

The ? symbol is used for declaring nullable types: $int? , $Type? , $dx:Type?.

Type Casting

Type casting statements are the same as those in C#.

xaml
<TextBlock Text="{DXBinding '(double)1'}"/>
<TextBlock Text="{DXBinding '(PropertyA as $dx:DXWindow).CurrentWindow'}"/>

Attached Properties

Attached Properties are used in the same way as those in standard bindings. Note that the “ $ “ (dollar) sign should be used to specify a defining type.

xaml
<TextBlock Text="{DXBinding '($Window.AttachedProperty).SubProperty'}"/>
<TextBlock Text="{DXBinding 'Property.($Window.AttachedProperty).SubProperty'}"/>

Operators

The DXBinding supports the following operators:

  • Arithmetic operators

  • Comparison and relational operators

  • Logical operators

  • Bitwise operators

  • new operator. Creates a new instance of a specified class.

  • Assignment operator =. Only the DXEvent and DXCommand extensions support this operator.

The operator priority is the same as in C#.

Special Words

The DXBinding language supports some reserved words. These words specify locations relative to the target’s position.

  • @s , @Self

  • @p , @TemplatedParent

  • @e , @ElementName

  • @r , @StaticResource

  • @a , @FindAncestor

  • @c , @DataContext

  • @Reference

When specifying the DXBinding.BackExpr property, you can use the @v or @value reserved word to access the input value.

xaml
<Control IsEnabled="{DXBinding Expr='!IsDisabled', BackExpr='!@v'}"/>
<Control Visibility="{DXBinding Expr='IsVisible ? `Visible` : `Collapsed`', BackExpr='@v == $Visibility.Visible'}"/>

When the DXCommand markup extension is used, you can use all the DXBinding’s special words plus the @parameter word to access the CommandParameter.

xaml
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Command="{DXCommand Execute='Save(@parameter)', CanExecute='CanSave(@parameter)'}" CommandParameter="{DXBinding @e(tb).Text}"/>

The DXEvent markup extension supports all the DXBinding’s special words plus the @sender and @args words to access the event sender and event arguments.

xaml
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(@sender.Content, @args, @e(tb).Text)'}"/>

Typization

DXBinding , DXCommand , DXEvent use interpretation. This allows using dynamic typization, so you do no need to cast values.

Value1 and Value2 can be of different types in the code sample below:

xaml
{DXBinding 'BooleanValue ? IntegerValue : StringValue'}

Such expressions are invalid in C#.

Limitations

  • Generic types are not supported.
  • Nested types are not supported.
  • Non-latin symbols are not supported in property names.
  • The @Reference special word is not supported in DataTemplates.