- Notifications
You must be signed in to change notification settings - Fork0
Specify complex expressions and use custom functions in shape templates
License
DevExpress-Examples/wpf-diagram-use-custom-functions-in-shape-templates
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This example uses complex expressions and custom functions to calculate theShapeTemplate'sParameter value. You can use custom expressions or functions to implement complex logic forParameters (for example, a circular motion).
In this example, the customSector shape allows users to specify its angle:
ShapeTemplates accept functions that implement theICustomFunctionOperator interface.Criteria Language Syntax allows you to calculate shapeParameters.
To create a custom calculation function, you must:
- Create a function class that implements theICustomFunctionOperator interface.
- Use theCriteriaOperator.RegisterCustomFunction method to register this function.
publicclassCreateArcPoint:ICustomFunctionOperator{privatestaticreadonlyCreateArcPointinstance=newCreateArcPoint();publicstaticvoidRegister(){CriteriaOperator.RegisterCustomFunction(instance);}publicstaticvoidUnregister(){CriteriaOperator.UnregisterCustomFunction(instance);}publicstringName=>nameof(CreateArcPoint);publicTypeResultType(paramsType[]operands){returntypeof(double);}publicobjectEvaluate(paramsobject[]operands){if(operands.Length==3&&operands[0]isdoubleX&&operands[1]isdoubleY&&operands[2]isstringaxe){if(axeis"X")returnX>0.5?X:0.5;returnX>0.5?Y:1;}elsereturnnull;}}
<ShapeTemplatex:Key="{ShapeKey Sector}"DefaultSize="120, 120"><StartX="0.5"Y="0" /><LineX="0.5"Y="0.5"/><LineX="(COS(P0) + 1)/2"Y="(SIN(P0) + 1)/2" /><ArcX="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)"/><ArcX="0.5"Y="0"Direction="Counterclockwise"Size="CreateSize(W/2, H/2)" /><ShapeTemplate.ConnectionPoints><ShapePointX="0.5"Y="1" /><ShapePointX="1"Y="0.5" /><ShapePointX="0.5"Y="0" /><ShapePointX="0"Y="0.5" /></ShapeTemplate.ConnectionPoints><ShapeTemplate.Parameters><ParameterDefaultValue="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)
About
Specify complex expressions and use custom functions in shape templates
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.
