Jump to: navigation, search

Changes


EvalExpression

744 bytes added, 12:28, 7 August 2019
/* Example */
The EvalExpression control allows to evaluate a C# expression from within XAML markup. The ''Expression'' has to be a single-line, valid C# expression ("Lambda") and has to return a single value; expressions can also reference names of subordinate [[EvalExpression#Parameters|EvalExpressionParameter]] items.
=== Example Examples === ==== Simple Calculation ====
The following example shows how to use the control with three parameters, where the first two are user input (Textbox ''Param0'' and ''Param1'') and the third one is a property from its DataContext (ViewModel). The evaluated ''Result'' is then bound to a Textblock for output in the UI.
</StackPanel>
</source>
 
Lets assume that the Textbox ''Param0'' contains a text of 42 and ''Param1'' contains a text of 43. If ''Expression'' now contains <code>(P0 + P1) *2</code> then the result would display 170.
 
==== Setting a calculated Property Value ====
The following example shows how to create a button that adds and stores +5 to a numeric property value named ''MP_EXAMPLE'', every time it is pressed:
 
<source lang = "xml">
<Grid xmlns:ctrls="using:UBIK.WinX.Controls">
<ctrls:EvalExpression x:Name="Evaluator" Expression="&quot;MP_EXAMPLE|&quot; + (P0 + 5)">
<ctrls:EvalExpressionParameter Name="P0" Value="{Binding Values[MP_EXAMPLE], Converter={StaticResource ToType}, ConverterParameter='System.Int32'}" />
</ctrls:EvalExpression>
<Button Content="Test" Command="{Binding SetPropertyValueAndValidateCommand}" CommandParameter="{Binding ElementName=Evaluator, Path=Result}"/>
</Grid>
</source>
[[Category:Pages with broken file links|EvalExpression]]