locked
Changing the Position of a Button or Any Control at Runtime... RRS feed

  • Question

  • Dear all,

    i need to move my control (change the position) like imagebox or button during runtime  in wpf c#. googling did not help me neither did msdn answers which seems to way old.

    regards

    Monday, August 20, 2012 4:36 PM

Answers

  • Look at TranslateTransform. You can apply this at runtime and it will move the control.

    Or change the control's Margin, Canvas.Left/Top.

    You can animate the changes.

     

    Regards,
    Pete


    #PEJL

    • Proposed as answer by Reed Copsey, JrMVP Monday, August 20, 2012 4:57 PM
    • Marked as answer by Kee Poppy Monday, September 3, 2012 5:42 AM
    Monday, August 20, 2012 4:41 PM
  • Also, if you have the control within some type of layout object (like a Grid), you can typically use the appropriate attached properties to move it within the control.

    For example, you can use Grid.SetRow(theButton, 3); to move the button to the grid's 4th row.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Kee Poppy Monday, September 3, 2012 5:42 AM
    Monday, August 20, 2012 4:57 PM

All replies

  • Look at TranslateTransform. You can apply this at runtime and it will move the control.

    Or change the control's Margin, Canvas.Left/Top.

    You can animate the changes.

     

    Regards,
    Pete


    #PEJL

    • Proposed as answer by Reed Copsey, JrMVP Monday, August 20, 2012 4:57 PM
    • Marked as answer by Kee Poppy Monday, September 3, 2012 5:42 AM
    Monday, August 20, 2012 4:41 PM
  • Also, if you have the control within some type of layout object (like a Grid), you can typically use the appropriate attached properties to move it within the control.

    For example, you can use Grid.SetRow(theButton, 3); to move the button to the grid's 4th row.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Kee Poppy Monday, September 3, 2012 5:42 AM
    Monday, August 20, 2012 4:57 PM