| version = 3.2+ in UBIK.UWP 1.0+ in UBIK.Xamarin
}}
== Concept ==
{{Hint|When writing expressions in XAML code, you have to avoid (escape) special characters. There are useful [https://www.freeformatter.com/xml-escape.html online tools] for this.}}
{{Hint|When writing expressions, it's always better (even necessary in some cases) to write them in their full forms. For example, while <nowiki>Bool_A || Bool_B</nowiki> is a valid expression, you should still write <nowiki>Bool_A==true || Bool_B==true</nowiki> instead.}}
{{Hint|If you want to use bindings in EvalExpressionParameters, a lot of the times you need to add <nowiki>Context="{Binding}"</nowiki> to the EvalExpression. This is because child UI elements (parameters in this case) do not inherit the binding context of the parent by default. Manually setting the context that way ensures that the same binding expressions that work outside the EvalExpression also work inside. Although this is not necessary if the binding you use explicitly refers to a named UI element.}}
==== Evaluation without parameters ====
<TextBlock
Foreground="White"
Text="Some Text"
Visibility="{Binding ElementName=Evaluator, Path=Result, Converter={StaticResource BoolToVisConverter}}" />
</StackPanel>
<Label
TextColor="#00000"
IsVisible="{Binding Path=Result, Source={x:Reference Evaluator}, Converter={StaticResource NullToBoolConverterBoolToBool}}" />
</StackLayout>
</source>
<StackLayout xmlns:ctrls="clr-namespace:UBIK.CPL.Controls;assembly=UBIK.CPL">
<Editor x:Name="Expression"/>
<Editor x:Name="P0Param0" WidthRequest="32"/> <Editor x:Name="P1Param1" WidthRequest="43"/>
<ctrls:EvalExpression x:Name="Evaluator" Expression="{Binding Path=Text, Source={x:Reference Expression}}" Context="{Binding}">
<ctrls:EvalExpressionParameter Name="P0" Value="{Binding Path=WidthRequest, Source={x:Reference P0Param0}}" /> <ctrls:EvalExpressionParameter Name="P1" Value="{Binding Path=WidthRequest, Source={x:Reference P1Param1}}" />
</ctrls:EvalExpression>
<Label Text="{Binding Path=Result, Source={x:Reference Evaluator}}" />
==== Conditional statement ====
If / Or statements can also be evaluated using C# syntax.
In this case, if the result of the "Condi" parameter is true, namely if the context object's MP_STATUS property value equals to 0, P0's value will be displayed in the Label, otherwise P1's value will be displayed.
<tabs>
<tab name="UWP">
If / Or statements can be evaluated using the C# syntax P0==true ? P1 : P2.
In this case, if the result of the P0 expression is True, P1 will be effected. Otherwise, P2 will be.
<source lang = "xml">
<Grid xmlns:ctrls="using:UBIK.WinX.Controls">
<ctrls:EvalExpression x:Name="InitialiseParameterWhenNullEvaluator" Expression="(P0Condi ==null) true ? P1 P0 : P2P1" Context="{Binding}"> <ctrls:EvalExpressionParameter Name="P0Condi" Value="{Binding StoredProfileParametersValues[WPType1MP_STATUS], Converter={StaticResource EqualToTrueConverter}, ConverterParameter=0}" /> <ctrls:EvalExpressionParameter Name="P1P0" Value="WPType1=1State1" /> <ctrls:EvalExpressionParameter Name="P2P1" Value="{Binding ElementName=InitialiseParameter, Path=Result}State2" />
</ctrls:EvalExpression>
<TextBlock Text="{Binding ElementName=Evaluator, Path=Result}" />
</Grid>
</source>
<tab name="Xamarin">
If / Or statements can also be evaluated using various C# syntax.
In this case, if the result of the P0 expression is true P00 will be used, if P1 is true P10 will be used.
<source lang = "xml">
<Grid xmlns:ctrls="clr-namespace:UBIK.CPL.Controls;assembly=UBIK.CPL">
<controlsctrls:EvalExpression x:Name="Evaluator" Expression="P0 Condi == true ? P00 P0 : (P1 == true ? P10)" Context="{Binding}"> <controlsctrls:EvalExpressionParameter Name="P0Condi" Value="{Binding Values[MP_STATUS], Converter={StaticResource EqualityToBool}, ConverterParameter=0}" /> <controlsctrls:EvalExpressionParameter Name="P00P0" Value="State1" /> <controlsctrls:EvalExpressionParameter Name="P1" Value="{Binding Values[MP_STATUS], Converter={StaticResource EqualityToBool}, ConverterParameter=10}" /> <controls:EvalExpressionParameter Name="P10" Value="State2" /> </controlsctrls:EvalExpression>
<Label Text="{Binding Path=Result, Source={x:Reference Evaluator}}" />
</Grid>
</tab>
</tabs>
==See also==
[[Category:WinX|EvalExpression]]
[[Category:Xamarin|EvalExpression]]
[[Category:XAML|EvalExpression]]