首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

Silverlight中如何获取Canvas子控件的位置坐标

2012-11-07 
Silverlight中怎么获取Canvas子控件的位置坐标Silverlight中怎么获取Canvas子控件的位置坐标[解决办法]Can

Silverlight中怎么获取Canvas子控件的位置坐标
Silverlight中怎么获取Canvas子控件的位置坐标

[解决办法]
Canvas.GetLeft(ChildElement)
 Canvas.GetTop(ChildElement)
[解决办法]
foreach (var item in MyCanvas.Children)
{
var box=item as BoxControl;
if (box.PtreeNodeId != null)
{
foreach (var pItem in MyCanvas.Children)
{
var pBox = pItem as BoxControl;
#region 计算连线两点的坐标
if (pBox.TreeNodeId == box.PtreeNodeId)
{
pMarginToTop = Canvas.GetTop(pItem);
marginToTop = Canvas.GetTop(item);
if (pMarginToTop > marginToTop)
{
boxX1 = Canvas.GetLeft(item) + box.Width / 2;
boxY1 = Canvas.GetTop(item);

pBoxX2 = Canvas.GetLeft(pItem) + pBox.Width / 2;
pBoxY2 = Canvas.GetTop(pItem) + pBox.Height;
}
else if (pMarginToTop < marginToTop)
{
boxX1 = Canvas.GetLeft(item) + box.Width / 2;
boxY1 = Canvas.GetTop(item) + box.Height;

pBoxX2 = Canvas.GetLeft(pItem) + pBox.Width / 2;
pBoxY2 = Canvas.GetTop(pItem);
}
else
{
pMarginToLeft = Canvas.GetLeft(pItem);
marginToLeft = Canvas.GetLeft(item);
if (pMarginToLeft > marginToLeft)
{
boxX1 = Canvas.GetLeft(item) + box.Width;
boxY1 = Canvas.GetTop(item) + box.Height / 2;

pBoxX2 = Canvas.GetLeft(pItem);
pBoxY2 = Canvas.GetTop(pItem) + pBox.Height / 2;
}
else if (pMarginToLeft < marginToLeft)
{
boxX1 = Canvas.GetLeft(item);
boxY1 = Canvas.GetTop(item) + box.Height / 2;

pBoxX2 = Canvas.GetLeft(pItem) + pBox.Width;
pBoxY2 = Canvas.GetTop(pItem) + pBox.Height / 2;
}
}


#endregion

热点排行