This example uses complex expressions and custom functions to calculate the ShapeTemplate's Parameter value. You can use custom expressions or functions to implement complex logic for Parameters (for example, a circular motion).
In this example, the custom Sector shape allows users to specify its angle:
ShapeTemplates accept functions that implement the ICustomFunctionOperator interface. Criteria Language Syntax allows you to calculate shape Parameters.
To create a custom calculation function, you must:
- Create a function class that implements the ICustomFunctionOperator interface.
- Use the CriteriaOperator.RegisterCustomFunction method to register this function.
public class CreateArcPoint : ICustomFunctionOperator {
private static readonly CreateArcPoint instance = new CreateArcPoint();
public static void Register() {
CriteriaOperator.RegisterCustomFunction(instance);
}
public static void Unregister() {
CriteriaOperator.UnregisterCustomFunction(instance);
}
public string Name => nameof(CreateArcPoint);
public Type ResultType(params Type[] operands) {
return typeof(double);
}
public object Evaluate(params object[] operands) {
if (operands.Length == 3
&& operands[0] is double X
&& operands[1] is double Y
&& operands[2] is string axe) {
if (axe is "X")
return X > 0.5 ? X : 0.5;
return X > 0.5 ? Y : 1;
}
else
return null;
}
}<ShapeTemplate x:Key="{ShapeKey Sector}" DefaultSize="120, 120">
<Start X="0.5" Y="0" />
<Line X="0.5" Y="0.5"/>
<Line X="(COS(P0) + 1)/2" Y="(SIN(P0) + 1)/2" />
<Arc X="CreateArcPoint((COS(P0) + 1)/2, (SIN(P0) + 1)/2, 'X')"
Y="CreateArcPoint((COS(P0) + 1)/2, (SIN(P0) + 1)/2, 'Y')"
Direction="Counterclockwise"
Size="CreateSize(W/2, H/2)"/>
<Arc X="0.5" Y="0" Direction="Counterclockwise" Size="CreateSize(W/2, H/2)" />
<ShapeTemplate.ConnectionPoints>
<ShapePoint X="0.5" Y="1" />
<ShapePoint X="1" Y="0.5" />
<ShapePoint X="0.5" Y="0" />
<ShapePoint X="0" Y="0.5" />
</ShapeTemplate.ConnectionPoints>
<ShapeTemplate.Parameters>
<Parameter DefaultValue="0"
Point="CreatePoint((COS(P) + 1)/2*W, (SIN(P) + 1)/2*H)"
Value="atn2(P.Y/H*2-1, P.X/W*2-1)"
Min="-3.14" Max="3.14" />
</ShapeTemplate.Parameters>
</ShapeTemplate>(you will be redirected to DevExpress.com to submit your response)
