wpf-115777-mvvm-framework-dxbinding-language-specification.md
DevExpress binding mechanism uses its own language. This language combines C# and XAML rules. This topic describes these rules in detail.
The following literals are used in the same way as those in C#.
<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.
<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.
<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:
<TextBlock Text="{DXBinding Expr='`a`[0]'}"/>
The following properties are used in the same way as those in C#.
<!--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>
You can invoke functions inside the DXBinding ‘s expression and pass parameters to them.
<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)'}"/>
The indexer is used in the same way as the one in C#.
<TextBlock Text="{DXBinding '[1]'}"/>
<TextBlock Text="{DXBinding 'Property[1+1]'}"/>
The DXBinding extension does not support notifications for indexer properties.
Type definitions start with the $ symbol.
There are some primitive types: $int , $double , …, $string , $object , $bool.
The XAML engine resolves the other types.
<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.
<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 statements are the same as those in C#.
<TextBlock Text="{DXBinding '(double)1'}"/>
<TextBlock Text="{DXBinding '(PropertyA as $dx:DXWindow).CurrentWindow'}"/>
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.
<TextBlock Text="{DXBinding '($Window.AttachedProperty).SubProperty'}"/>
<TextBlock Text="{DXBinding 'Property.($Window.AttachedProperty).SubProperty'}"/>
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#.
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.
<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.
<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.
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(@sender.Content, @args, @e(tb).Text)'}"/>
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:
{DXBinding 'BooleanValue ? IntegerValue : StringValue'}
Such expressions are invalid in C#.