[已解决]DiagramShape可否添加连接点
本帖最后由 yuhuimoon 于 2015-12-17 13:39 编辑目前在使用Dev15.2.4,使用XtraDiagram接口创建DiagramShape对象,默认的链接锚点只有四个(上下左右),能否增加某侧的连接点呢?如图所示:
我还未测试,从官方图片来看肯定可以。
http://7jpreg.com1.z0.glb.clouddn.com/dev-winforms-diagram-15-2.jpg 才安装看了一下,选择connector即可。 seamone 发表于 2015-12-16 14:30
才安装看了一下,选择connector即可。
请教下,我运行官方demo,如图所示,默认创建了4个锚点,我在属性里也只能看到left、top、right、bottom四个可供筛选,没有找到自定义位置的选项。不知道你是在哪里试过的呀?Demo还是自己程序写出来的?
本帖最后由 yuhuimoon 于 2015-12-17 13:43 编辑
该问题已经解决。
下面是部分代码,供大家参考:
需要先定义xaml描述文件,用于定义shape的样式,具体方法可以参考官方文档。其中,ShapePoint就是我的自定义锚点
<p:ResourceDictionary xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="clr-namespace:DevExpress.Diagram.Core.Shapes;assembly=DevExpress.Diagram.v15.2.Core">
<ShapeTemplate x:Key="{ShapeKey CustomShape1}" DefaultSize="100,100" Columns="*;P0;*" Rows="*;P0;*">
<Start X="1" Y="0" />
<Line X="2" Y="0" />
<Line X="2" Y="1" />
<Line X="3" Y="1" />
<Line X="3" Y="2" />
<Line X="2" Y="2" />
<Line X="2" Y="3" />
<Line X="1" Y="3" />
<Line X="1" Y="2" />
<Line X="0" Y="2" />
<Line X="0" Y="1" />
<Line X="1" Y="1" />
<ShapeTemplate.ConnectionPoints>
<ShapePoint X="1.5" Y="0" />
<ShapePoint X="3" Y="1.5" />
<ShapePoint X="1.5" Y="3" />
<ShapePoint X="0" Y="1.5" />
<ShapePoint X="0" Y="0" />
<ShapePoint X="3" Y="3" />
</ShapeTemplate.ConnectionPoints>
<ShapeTemplate.Parameters>
<Parameter DefaultValue="20"
Point="CreatePoint((P + W) / 2, H)"
Value="2 * P.X - W"
Min="100" Max="Min(W, H)" />
</ShapeTemplate.Parameters>
</ShapeTemplate>
</p:ResourceDictionary>
然后定义自定义shape的构建类:
public static class CustomShapeBuilder
{
static System.Windows.FrameworkElement element = null;
public static string getCustomShapeName(string id)
{
return DevExpress.Diagram.Core.DiagramToolboxRegistrator.GetStencil(id).Name;
}
public static DiagramStencil GetCustomStencil(string id)
{
return DevExpress.Diagram.Core.DiagramToolboxRegistrator.GetStencil(id);
}
public static void RegisterCustomShapes()
{
if (element == null)
{
element = new System.Windows.FrameworkElement();
}
var dict = new System.Windows.ResourceDictionary();
dict.Source = new Uri("E:\\DiagramResources.xaml", UriKind.RelativeOrAbsolute);
DevExpress.Diagram.Core.DiagramToolboxRegistrator.RegisterShapes("CustomShapes", () => "Custom Shapes", dict, getCustomShapeName);
}
}
最后在需要创建的地方调用,有点需要说明,我的程序没有使用DiagramToolBox工具箱,只是获取了DiagramShape对象:
CustomShapeBuilder.RegisterCustomShapes();
DiagramStencil myStencil = CustomShapeBuilder.GetCustomStencil("CustomShapes");
ShapeDescription myDescription = myStencil.GetShape("CustomShape1");
DiagramShape _shape = new DiagramShape(myDescription, 0, 0, 100, 100, theShape.Content);
运行程序,创建出了一个Shape,一共有六个锚点(上、下、左、右、左上、右下):
页:
[1]