在画布上查找控件位置 [英] Find control position on canvas
问题描述
我有一个画布,其中包含一些文本块,我需要找到顶部,左角点,我在xaml分配它们。如何获得这两个属性?当我在画布上的框架元素循环时,我似乎找不到那些列出的属性。
I have a canvas which contains a few textblocks and I need to find the top, left corner points that I assigned them in xaml. How can I get those two properties? When I loop through the framework elements on the canvas I can't seem to find those to properties listed.
推荐答案
如何获取值:
foreach(FrameworkElement fe in canvas.Children){
// example 0
double top=(double)fe.GetValue(Canvas.TopProperty);
double left=(double)fe.GetValue(Canvas.LeftProperty);
// example 1
double top1=Canvas.GetTop(fe);
double left1=Canvas.GetLeft(fe);
}
请参阅 http://msdn.microsoft.com/en-us/library/ms749011.aspx 和
< a href =http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.top.aspx =nofollow noreferrer> http://msdn.microsoft.com/en -us / library / system.windows.controls.canvas.top.aspx
了解更多信息
See http://msdn.microsoft.com/en-us/library/ms749011.aspx and http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.top.aspx for more information
这篇关于在画布上查找控件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!