Math expression markup extension #18363
tkefauver
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This extension lets you bind
double
orbool
type properties to a parameterized equation which has proven pretty handy so I thought I'd share it :)It allows binding to 4 variables
a
,b
,c
,d
(arbitrarily 4 and assumes they're all doubles). Then you provide anexp
string that uses those variable names to evaluate the result which can be adouble
orbool
(when you setIsBoolResult=true
).Random examples:
A variable
FontSize
based on a dimension of some control:FontSize="{local:MathBinding a={Binding $parent[Grid].Bounds.Width}, exp=(a/3)+1}"
Conditionally hiding a view when something is too big let's say which needs a
bool
result. This requires theexp
to use an IF(exp,true val,false val) syntax (or anything MathEval supports):IsVisible="{local:MathBinding a={Binding Bounds.Width,ElementName=SomeElement}, b={Binding Bounds.Width,ElementName=SomeOtherElement}, IsBoolResult=true, exp=IF(a-b<0,1,0)}"
Notes:
When bound variables aren't defined/imaginary(yet) it just defaults them to 0 but you could change that behavior.
Also to avoid divide by zero issues its a good idea to add a small number to any divisor variables like
exp=a/(b+0.001)
To use it you need to add MathEval:
dotnet add package org.matheval
Code:
Beta Was this translation helpful? Give feedback.
All reactions