连接两个形状在一起,Silverlight 2中 [英] Connecting two shapes together, Silverlight 2
问题描述
我在寻找连接或两个形状或物体与线粘合在一起。这些形状会动态生成的,这意味着我将调用后端的Web服务,以确定有多少对象/形状需要创建。一旦这是确定的,我需要有对象/连接在一起的形状
方法签名可能看起来像这样(类似于Visio中的绘图功能):
GlueTogether(objButton1,objButton2);
我可能需要获得每个矩形形状或按钮的位置,以确定起跑线点。然后确定第二个形状/物体位置画线。
任何帮助或建议将是伟大的!
- 使用一个路径或堆叠顺序或Z指数形状下方的行
- 使用instance.TransformToVisual()拿到这两个中心点之间的变换每个形状
- 使用变换变换每个形状的中心点
- 画一条线。
VAR transform1 = shape1.TransformToVisual(shape1.Parent为的UIElement);
VAR transform2 = shape2.TransformToVisual(shape2.Parent为的UIElement);
变种lineGeometry =新LineGeometry()
{
StartPoint可以= transform1.Transform(新点(shape1.ActualWidth / 2,shape1.ActualHeight / 2.0)),
终点= transform2.Transform(新点(shape2.ActualWidth / 2.0,shape2.ActualHeight / 2.0))
};
VAR路径=新路径()
{
数据= lineGeometry
};
I'm looking to connect or glue together two shapes or objects with a Line. These shapes will be generated dynamically, meaning I'll be calling a Web service on the backend to determine how many objects/shapes need to be created. Once this is determined, I'll need to have the objects/shapes connected together.
The method signature may look like this (similar to Visio's drawing capabilities):
GlueTogether(objButton1, objButton2);
I may need to get the position of each Rectangle shape or Button to determine where the starting Line point is. Then determine the second shape/objects position to draw the line.
Any help or suggestions would be great!
- Use a Path or a Line below the shapes in stacking order or z index
- Use instance.TransformToVisual() to get the transform of each shape
- Use the transform to transform the centerpoint of each shape
- Draw a line between the two centerpoints.
var transform1 = shape1.TransformToVisual(shape1.Parent as UIElement);
var transform2 = shape2.TransformToVisual(shape2.Parent as UIElement);
var lineGeometry = new LineGeometry()
{
StartPoint = transform1.Transform(new Point(shape1.ActualWidth / 2, shape1.ActualHeight / 2.0)),
EndPoint = transform2.Transform(new Point(shape2.ActualWidth / 2.0, shape2.ActualHeight / 2.0))
};
var path = new Path()
{
Data = lineGeometry
};
这篇关于连接两个形状在一起,Silverlight 2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!