2012-09-09 7 views
0

캔버스에서 텍스트 블록을 동적으로 만들고 이동해야하는 곳에서 레이아웃을 저장하고 레이아웃을로드하는 응용 프로그램이 있습니다. 문제 나는 textblock의 위치를 ​​얻으려고 피곤하다. 나는이 두 가지 방법을 시도하지만 컨트롤에서Contol Position 런타임에 이동 후 업데이트되지 않습니다.

item.GetValue(TranslateTransform.XProperty).ToString();//always give zero 
Canvas.GetTop(item);//always gives the initial position, does not update after dragging. 
+0

항목은 무엇 클래스 : 상태를로드 할 때

foreach (UIElement el in mapGrid.Children) { XElement control = new XElement("control"); var ele = (HumanWorkspace)el; Vector v = VisualTreeHelper.GetOffset(el); double x = v.X; double y = v.Y; XAttribute atd = new XAttribute("direction", ele.Direction.ToString("d")); XAttribute atx = new XAttribute("x", v.X.ToString()); XAttribute aty = new XAttribute("y", v.Y.ToString()); control.Add(atd); control.Add(atx); control.Add(aty); controls.Add(control); } 

이 좌표를 설정? –

+0

항목이 텍스트 블록입니다. – thewayman

답변

1

얻기 좌표를 작동하지 :

foreach (XElement ele in doc.Elements("controls")) 
      { 
       var con = new HumanWorkspace(); 
       con.Direction = (WorkspaceDirection)int.Parse(ele.Attribute("direction").Value); 
       con.SetValue(TranslateTransform.XProperty, double.Parse(ele.Attribute("x").Value)); 
       con.SetValue(TranslateTransform.YProperty, double.Parse(ele.Attribute("y").Value)); 
      } 
관련 문제