2012-09-09 43 views
0

我有一個應用程序需要在後期動態創建和移動文本框中的文本塊,然後保存佈局和加載佈局。 我正面臨的問題是很累人的文本塊的位置。 我想這兩方法,但它不工作控件位置在運行時移動它後不更新

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

什麼類的項目? –

+0

項目是文本塊 – thewayman

回答

1

獲取COORDS從控制:

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); 
     } 

設置COORDS加載狀態時:

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)); 
      } 
相關問題